Let's say in the src folder, we have two files, one is typescript file someFeatures.ts
, the other is js file someFeatures.js
,so their main file name is the same, and contain the same content,just the extension name is different, so in the main index.ts
file, I import the dependency as:
import { sizeFormatter, costFormatter } from "./someFeatures";
so how does the compile know which one I'm referring to? it could be someFeatures.ts
or someFeatures.js
?
If the allowJs
option in tsconfig.json
is set to false then Typescript compiler will ignore someFeatures.js
like any .js
file when it resolves imports. It will take only .ts.tsx.d.ts
into account as explained here under How TypeScript resolves modules heading.
If the allowJs
option in tsconfig.json
is set to true then Typescript compiler will specifically ignore someFeatures.js
as a "possible output" due to presence of someFeatures.ts
as explained there , search for "possible outputs".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.