You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
typeRoots falls back to automatic inclusion of packages #774
However, when types could not be found in the compilerOptions.typeRoots folders, compiler falls back to the automatic inclusion of Types (@types) packages.
that is not accurate.. there are two parts of the process. there are global pacakges (e.g. node, jquery, etc..) and there are modules (e.g. react).
typeRoots controls the global side of things.. that means @types\node will be included even though you never have an import in your project like import ... from "node".
for modules, e.g. import .. from "react", module resolution will go through the normal process, and will try to find a module react. part of that is to fall back to node_modules\@types\react if non better was found.
Mohamed Hegazy (@mhegazy) it is already about automatic inclusion of global packages, not about modules imported by import statements.
So, import statements fallback to node_modules\@types but also it fallback when types in typeRoots folders do not exist, even though it is not that significant.
You are right, it does not fallback with an empty typeRoots folder. So, i find out what i was doing. I have an empty sub-folder with my modules name under the typeRoots folder so, it causes the module folder resolved by fallback to the node_modules/@types.
tsc --listFiles --traceResolution --typeRoots someFolder ./wwwroot/js/site.ts
======== Resolving type reference directive 'mymodule', containing file 'D:/TestProject/__inferred type names__.ts', root directory 'someFolder'. ========
Resolving with primary search path 'someFolder'.
File 'someFolder/mymodule/package.json' does not exist.
File 'someFolder/mymodule/index.d.ts' does not exist.
Looking up in 'node_modules' folder, initial location 'D:/TestProject'.
File 'D:/TestProject/node_modules/mymodule.d.ts' does not exist.
File 'D:/TestProject/node_modules/@types/mymodule/package.json' does not exist.
File 'D:/TestProject/node_modules/@types/mymodule.d.ts' does not exist.
File 'D:/TestProject/node_modules/@types/mymodule/index.d.ts' exist - use it as a name resolution result.
Resolving real path for 'D:/TestProject/node_modules/@types/mymodule/index.d.ts', result 'D:/TestProject/node_modules/@types/mymodule/index.d.ts'.
======== Type reference directive 'mymodule' was successfully resolved to 'D:/TestProject/node_modules/@types/mymodule/index.d.ts', primary: false. ========
C:/Users/exp/AppData/Roaming/npm/node_modules/typescript/lib/lib.d.ts
wwwroot/js/site.ts
D:/TestProject/node_modules/@types/mymodule/index.d.ts
Activity
mhegazy commentedon Jun 6, 2018
that is not accurate.. there are two parts of the process. there are global pacakges (e.g. node, jquery, etc..) and there are modules (e.g. react).
typeRootscontrols the global side of things.. that means@types\nodewill be included even though you never have an import in your project likeimport ... from "node".for modules, e.g.
import .. from "react", module resolution will go through the normal process, and will try to find a modulereact. part of that is to fall back tonode_modules\@types\reactif non better was found.expressiveco commentedon Jun 7, 2018
Mohamed Hegazy (@mhegazy) it is already about automatic inclusion of global packages, not about modules imported by import statements.
So, import statements fallback to
node_modules\@typesbut also it fallback when types in typeRoots folders do not exist, even though it is not that significant.mhegazy commentedon Jun 7, 2018
i do not think this is true.
expressiveco commentedon Jun 7, 2018
Mohamed Hegazy (@mhegazy) I tested it, will check again.
mhegazy commentedon Jun 7, 2018
c:\test\774>tree /f . │ a.ts │ package.json │ └───node_modules └───@types └───node index.d.ts inspector.d.ts LICENSE package.json README.md c:\test\774>tsc --v Version 2.9.1 c:\test\774>tsc --listFiles a.ts C:/Users/mhegazy/AppData/Roaming/npm/node_modules/typescript/lib/lib.d.ts a.ts c:/test/774/node_modules/@types/node/inspector.d.ts c:/test/774/node_modules/@types/node/index.d.ts c:\test\774>tsc --typeRoots ./a --listFiles a.ts C:/Users/mhegazy/AppData/Roaming/npm/node_modules/typescript/lib/lib.d.ts a.tsexpressiveco commentedon Jun 7, 2018
Try this;
mhegazy commentedon Jun 7, 2018
mhegazy commentedon Jun 7, 2018
if i were to guess, you have an
importsomewhere in your file.expressiveco commentedon Jun 8, 2018
You are right, it does not fallback with an empty typeRoots folder. So, i find out what i was doing. I have an empty sub-folder with my modules name under the typeRoots folder so, it causes the module folder resolved by fallback to the
node_modules/@types.mhegazy commentedon Jun 8, 2018
Yes. the assumption here is that every subfolder in your typesRoot is a declaration package and not a random folder.