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. Lead Instructor @GA. Former Data Analytics Instructor and Mentor at Academy Xi, Digital Accelerator and Facilitator at PwC Digital Academy. We upskilled 200 management consultants.
Location
Sydney, Australia
Education
Master of Data Science, University of Technology Sydney
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 🙂