TCMiranda / joi-extract-type

Provides native type extraction from Joi schemas for Typescript
MIT License
151 stars 27 forks source link

Typescript 3.9 compatibility #33

Closed Rauttis closed 4 years ago

Rauttis commented 4 years ago

joi-extract-type @ 15.0.2 appears to be incompatible with Typescript 3.9 and above (at the time of writing 3.9.2).

Most of the errors seem to do with the usage of generics and circular references eg.: Type alias 'extractType' circularly references itself Type 'extractMap' is not generic

TCMiranda commented 4 years ago

Seems that typescript 3.7 made some changes about this that we may have to adapt to https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#more-recursive-type-aliases

beeequeue commented 4 years ago

It seems the issues start with 3.9 - 3.8.3 works fine.

rubengmurray commented 4 years ago

Yep, seeing the same issue here after running an npm install. package-lock TS 3.9.5

wspringer commented 4 years ago

This became pretty painful after VSCode started updating the version of TypeScript it's using. VSCode was no longer able to recognize the type. Switched to TypeScript 3.8.3 to make sure VSCode was able to make sense of it again.

image

rubengmurray commented 4 years ago

Yep^ - except I wasn't able to select a new dropdown from the same list that you've provided a screenshot of there @wspringer

I believe you can set it at a workspace level but I tend to have lots of projects open in the same instance of code, in which case the solution I've found is to override the default VSCode TS version based on the globally installed TS version via npm (mine is 3.8.3).

Open this file /Users/your_name/Library/Application Support/Code/User/settings.json

Add in "typescript.tsdk": "/usr/local/lib/node_modules/typescript/lib" (points to npm i -g typescript@3.8.3

Reload your editor.

bvallee-thefork commented 4 years ago

Basically, from the TypeScript team [^1]:

Certain things can be deferred if there's a different declaration to "pause" the circularity at. I don't want to commit any specific circular behavior to bug/not bug; it depends on a lot of different factors and is sensitive to exactly where TS tries to resolve certain conditionals.

So here is a fix to make the compiler of TypeScript 3.9.6 happy with Joi.extractType: https://github.com/TCMiranda/joi-extract-type/pull/35

[^1] https://github.com/microsoft/TypeScript/issues/39147#issuecomment-646120321

b-zurg commented 4 years ago

Thanks for this! Any ETA on a new release that includes this?