Does anybody know how to use this trick with Typescript? Say, I have a TS project with "type": "module" in package.json and "module" set to "esnext" in tsconfig.json. Then, I have 2 TS files in the same directory, e.g. a.ts and b.ts with a line in b.ts reading:
import{...}from'./a.js'
and it works fine after compilation with tsc (please notice the use of a.js instead of a in the import statrement -- this is a requirement for imports of local ESM modules)
But... when I replace import statement to
import{...}from'./a.js?q=hello'
then tsc throws error that it cannot find module.
The only solution that I know is to suppress TS error checking by adding @ts-ignore like that:
Data Scientist. PhD Candidate. AWS Data Hero. Former PwC Digital Accelerator at PwC Digital Academy we upskilled 200 management consultants🖋️Coffee N Learn newsletter
Does anybody know how to use this trick with Typescript? Say, I have a TS project with
"type": "module"inpackage.jsonand"module"set to"esnext"intsconfig.json. Then, I have 2 TS files in the same directory, e.g.a.tsandb.tswith a line inb.tsreading:and it works fine after compilation with
tsc(please notice the use ofa.jsinstead ofain the import statrement -- this is a requirement for imports of local ESM modules)But... when I replace
importstatement tothen
tscthrows error that it cannot find module.The only solution that I know is to suppress TS error checking by adding
@ts-ignorelike that:There is limited support for this, add this into your
tsconfig.json,Have a look at path-mapping
Great article by Lioness100 and thanks @servernoj for asking a thoughtful question and sharing with the DEV community 🙂