-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Bug: Priority of imports .json is higher ranked as .ts #47870
Comments
ref: #37582 |
@weswigham any thoughts? |
OP, for now, you can just use the |
Originally posted by @tonygiang in #37582 (comment) can you please publish a reproducer repo anything that we can run that shows that failure? |
Yes, here it is: ts-sandbox.zip And here is a screenshot showing the direct contradiction between VS Code's suggestion icon and the actual output: Tested on Node 16.14.0 LTS. |
this tripped me off a bit, I thought the node.js extension-less file resolution was preferring it seems the bug is actually in now, if you run |
Yeah... That's a |
@weswigham i know they are still working on it TypeStrong/ts-node#1361 and other issues i spot them from time to time in my projects at rollup plugin typescript we did also not handle all edge cases. i my self try to algin the typescript functionality with the rollup one so that we maybe do not need to both implement the resolve algos maybe when typescript did implement proper resolve algos we could drop plugin node-resolve |
I see the real issue now. Times like this makes me kind of want TypeScript to ship with a standard JIT engine so that issues don't get fragmented to different stacks. Deno runtime has a similar issue also stemming from running untranspiled .ts files directly. Instead of importing the There was apparently an Import Assertions proposal submitted to TC39 that is at Stage 3 at the time of writing which resolves this issue for good with an additional |
not sure what that would solve.
https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/#import-assertions keep in mind typescript is not down-leveling this syntax to a commonjs equivalent, although I'm thinking it could (or even should, at least when targeting commonjs/node.js), meaning you can use it only with a
https://nodejs.org/dist/latest-v17.x/docs/api/esm.html#import-assertions |
It has to do with tooling consistency. Currently, we have VS Code and TypeScript both developed by the same company with the expectation that .ts files are transpiled before execution. If a JIT engine was developed by the same company too, the best case scenario is that the developers walk into either VS Code or the JIT Engine with the other tool in mind and align expectation so that this would never become an issue. Maybe the JIT Engine will force a pre-transpile if it detects a .json file with the same name with a .ts file, or maybe VS Code will simply give you a warning in that case and now you can rename some files and get no more runtime surprise. The worst case scenario is that it became 1 issue instead of 2. |
@tonygiang there is also ongoing work on typed json as far as i am aware of your jit arrgument is valid and the conclusion that the other projects are breaking behavior is also correct. i think still that using rollup as loader would solve the issues at present i can workaround any issues like that via my rollup + plugin typescript setup but i was not able to isolate that into a useable generic product at the current point in time as there are many moving parts. i do not remember what deno did use to run code but it was a relativ simple zero configuration bundler that they use to run the code. So deno has no own code to run code they are creating bundlers it was parcel |
lets close this as it is not a typescript bug. but in the moduleResolution documentation on typescriptlang should maybe be a example in what order json gets loaded when it gets loaded. |
+1
If I turn on
resolveJsonModule
and put aMatchmakingConfig.ts
and aMatchmakingConfig.json
in the same path, a nasty unexpected behavior awaits:Allowing
.ts
suffix will let us specify.ts
files specifically.Originally posted by @tonygiang in #37582 (comment)
Solution
Priority needs to get changed anyway .ts needs to get resolved with a higher priority then .json
The text was updated successfully, but these errors were encountered: