-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type exports to package.json #40
Conversation
bump |
The types are located in the root folder next to the original files. Hence, it shouldn't be necessary to explicitly link to the files.. Before you make another PR, can you please explain how your typescript version doesn't find the type definitions? |
Sure. The lib i'm building is a module. Therefore all imports have to be precise. When I import e.g. "array" the linker doesn't look for a "array.js". It looks for an export statement in the package.json that matches "array". It doesn't assume things anymore.
If I try to import just "array" it uses the block at the bottom. But this block doesn't contain the type file reference. Therefore typescript can't find type definitions because the linker doesn't assume anything anymore. Of course I could just import "array.js" instead of the alias export statement. The entry for this string is pointing directly to a .js file instead of a block which allows the linker to see the file and therefore look for a |
So I ask you to please merge this pull request. Otherwise I can't use this lib (and y-protocols) with esmodule libs and would need to replace it. :/ |
Did you have a chance to take a look at this again? |
As I said before, the type declarations are located next to the original files. So "./dist/array.d.ts"` doesn't exist. This PR is untested and will break everyone else. So before you make another PR. Please explain why the current approach doesn't work. What is your setup? Why does it work for everyone else but you? Second, you need to change your PR to point to the actual type declarations: Third, you need to test the PR and ensure it actually works. Please also show me how I can verify that it works in the future. |
Nope. they exist. But okay. Since you prefer the top level type files I changed the code.
No. I've tested it locally and it works. It doesn't break anything since the export object is only used if typescript is using the ESM resolver.
Like I explained before here a full module setup relies only on the export object and doesn't assume the location of type files. I guess most of the people use the default configuration of typescript for module resolution which is the commonjs module resolver which still assumes the location of type files. I recorded this quick video to demonstrate the effect of the modified package.json . I used my lib's test cases because the tests are also written in typescript and therefore also use the ESM resolver. lib0-2022-12-02_12.31.35.mp4 |
btw: yjs exports the types correctly https://github.com/yjs/yjs/blob/main/package.json#L29 . That's why this lib doesn't produce such errors. |
Same as yjs/y-protocols#21