ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas πŸ“
MIT License
1.47k stars 31 forks source link

Probably all versions above `1.6.4` are not working with `preserveSymlinks` tsconfig option #88

Closed bayoudhi closed 2 years ago

bayoudhi commented 2 years ago

Hey, this is a cool library I really like the idea of inferring TS types from JSON schemas πŸ‘ŒπŸ»

Almost all the solutions I found are focused on generating types (via CLIs or code), this library is different & unique.

I found something interesting, all the recent versions (above 1.6.4) of this library are not working for me, I'm pretty sure my config is correct I'm using Typescript v4 and strict mode is enabled.

This is what I receive, the inferring is not working πŸ˜• Used the example in the Readme.

The interesting part is this, it looks like 1.6.4 is the most used version in the last week, so I test it and it's working perfectly!

Can anyone please confirm that versions above 1.6.4 work? or at least the recent one 2.5.5? Maybe I have something wrong on my side, thanks.

This is my config:

ThomasAribart commented 2 years ago

Hi @bayoudhi,

Interesting, I tried to reproduce the issue with the same Typescript version, without success:

Capture d’écran 2022-08-28 aΜ€ 18 10

Can you provide your tsconfig as well ?

bayoudhi commented 2 years ago

Hi @ThomasAribart

I think I found the cause, it's related to preserveSymlinks option in my tsconfig.json (as you guessed it's something related to tsconfig πŸ™‚)

// tsconfig.json
{
  "compilerOptions": {
    "preserveSymlinks": true
    // other options
  }
}

When turned on, inferring does not work, if I remove it or turn it off ("preserveSymlinks": false) inferring works as expected. I used the latest version 2.5.5 btw.

I have a monorepo project with multiple tsconfig files and modules, and I'm pretty sure preserveSymlinks is required, I need to check that.

If so can I use this library with my current tsconfig file? Maybe there's something we can do to make it work with preserveSymlinks, thanks.

bayoudhi commented 2 years ago

I have a monorepo project with multiple tsconfig files and modules, and I'm pretty sure preserveSymlinks is required, I need to check that.

Yep, preserveSymlinks is required in my case πŸ˜•

ThomasAribart commented 2 years ago

Nice catch, thanks ! I'll have a look ! The least I can do is add it as a requirement in the docs.

For what reason do you use preserveSymlinks options ? Sharing code across services ?

bayoudhi commented 2 years ago

Hi @ThomasAribart, thanks for the reply. I'm sorry for the late response.

To be honest, I'm still not sure what preserveSymlinks is used for πŸ˜… it's a monorepo project where some code is shared between different projects/services.

I have a monorepo project with multiple tsconfig files and modules, and I'm pretty sure preserveSymlinks is required, I need to check that.

Yep, preserveSymlinks is required in my case

I figured out that preserveSymlinks is not required in my project, and the error I received 3 days ago after disabling preserveSymlinks is not related to this option (I already fixed it) so I can use this library now without any issues πŸŽ‰

Thanks again for the fast replies and help πŸ™‚

I'm going to close this issue.