3 ms·
In your tsconfig.json [0]: "moduleResolution": "node16" In your TS files, even if the import is a file with the extension .ts (tsc will handle): import
by gnabgib 4y ago
In your tsconfig.json [0]:
"moduleResolution": "node16"
In your TS files, even if the import is a file with the extension .ts (tsc will handle):
import { test } from './importMe.js';
[0]: https://www.typescriptlang.org/tsconfig#moduleResolution https://www.typescriptlang.org/tsconfig#moduleResolution
- wdb 4y agoDidn’t they add a new option `allowImportingTsExtensions` to TypeScript 5 that allows you to use `.ts` in imports? I haven’t tried it but that’s what I understood from the blog article
- triyambakam 4y agoHeh, I came to write the same thing. It's somewhat annoying but works well.
- ultim8k 4y agoIt works but every single time I see it, I start swearing.
- noahtallen 4y agoRight, this is what people are arguing about in the issue. It’s honestly extraordinarily unintuitive and frustrating, and the team’s arguments are more philosophical than practical (along the lines of “typescript will never deviate from JavaScript language specification”). I’m not very sympathetic since the entire language is incompatible with a JS interpreter, and importing from a file that doesn’t actually exist is really poor DevX. I really wish the TS team had not forced people to decide between ESM (the future of JS modules) or importing files that don’t actually exist everywhere in the codebase.
- nikeee 4y agoI think it's the right solution, though I get that it confuses people. Given that the compiler only erases static type annotations, it should not touch the imports. > entire language is incompatible with a JS interpreter If this proposal will ever be accepted, TS will be (in large parts) valid JS: https://github.com/tc39/proposal-type-annotations https://github.com/tc39/proposal-type-annotations
- icholy 4y agoTell that to enums
- chatmasta 4y agoAs of 5.0 you can now use `--moduleResolution bundler` which may solve the main complaints from the issue (I admit I only skimmed it). [0] https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#moduleresolution-bundler https://devblogs.microsoft.com/typescript/announcing-typescr...