'same file name in typescript files and javascript files
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
?
Solution 1:[1]
allowJS: false
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.
allowJS: true
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".
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |