mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

Consider migrating away from `tsd` to support TS Native

Open chriskrycho opened this issue 1 month ago • 4 comments

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have searched existing issues to ensure the issue has not already been raised

Issue

Today, Mongoose’s type tests use tsd, which uses a fork of the TS compiler to validate the types. This makes it impossible to execute the test suite against the TypeScript native rewrite, and it is unclear what the future of tsd will be. Switching to use a type assertion library like expect-type (or any other that purely works with types, rather than forking the compiler) would make it possible to begin regularly testing Mongoose’s types against tsgo.

That in turn will allow early adopters (like Vanta, where I am actively trying to get us to be able to use tsgo!) to flush out issues and help get them fixes in the appropriate place.

chriskrycho avatar Oct 23 '25 15:10 chriskrycho

(Really sorry about my off-topic comments. Please ignore. I decided to suspend my account.)

ghost avatar Oct 24 '25 07:10 ghost

This should be doable with some caveats. The only helpers we use from tsd are expectType, expectAssignable, expectNotAssignable, and expectError. The first 3 are one-liners (at least with how Mongoose uses them). expectError is trickier to replace, but we could just use // @ts-expect-error for cases when we want to test that a certain bit of code is invalid.

We'll try this out in the next couple of weeks and see how it goes.

vkarpov15 avatar Oct 24 '25 14:10 vkarpov15

I’m pushing pretty hard on this for us, so I’m happy to see if I can push one up in the next couple days if you’d like! I can either use expect-type (which has the most robust type assertions I know of, and is my go-to for these kinds of things) or I can use the one-liners inline. Have a preference?

chriskrycho avatar Oct 24 '25 17:10 chriskrycho

Sure feel free to put together a PR using expect-type if you would like :+1:

vkarpov15 avatar Oct 29 '25 17:10 vkarpov15