-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New node_modules/@types lookup needs prodding to include node.d.ts in build #9208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What version of tsc are you using? what is the structure of your folder? can you share your tsconfig.json? here is my setup: C:\test\sandbox5>type test.ts
import * as fs from "fs";
var x = fs.readFileSync("c:\\test\\a.ts").toString();
console.log(x);
C:\test\sandbox5>tsc --v
Version 1.9.0-dev.20160616-1.0
C:\test\sandbox5>ls node_modules\@types
[.] [..] [mocha] [node]
C:\test\sandbox5>tsc --listFiles test.ts
C:/Users/mhegazy/AppData/Roaming/npm/node_modules/typescript/lib/lib.d.ts
test.ts
C:/test/sandbox5/node_modules/@types/mocha/index.d.ts
C:/test/sandbox5/node_modules/@types/node/index.d.ts |
This is using The project structure is like this:
Running Now if I move the files from
...then it compiles successfully and the file list also includes For context, some of our projects have multiple |
@RyanCavanaugh and @DanielRosenwasser we went back and forth on this, what is the recommendation here? |
So after reading through the design notes (#9086), I added |
IMO For example, if I have Now if I add |
you do not really need the "types" : [ "node", "mocha" ] |
OK, I missed that. But why isn't it walking the spine? #9086 says:
Which suggests our project should compile without needing either |
Yep, |
We are getting the documentation ready. should have something up in the coming weeks. |
Great, thanks. So I guess the only question left is whether EDIT: I'd also be interested to know why |
Fixed by #10670. |
I had related requirement. Is there any way to include all the types file name under typeroots directory, without typing name of all the types, like using any pattern. Existing syntax: Required syntax: |
@krvikash35 the behaviour I'm seeing now in the nightlies is that tsc automatically finds all types installed in node_modules/@types, without having to specify either |
I had tried with Version 2.0.2, will check it properly once. |
Actually whatever you told is right..i dont have to mention even typeRoots or types name...but before this...i was using that ts with atom editor..so from command line it is working as expected but when i am using the same ts service as atom-plugin, i have to explicitly specify all types name .. |
After reading @DanielRosenwasser's new blog post about the support in typescript@next for looking up type declarations directly from
node_modules/@types/<libname>
, I did as the post suggested and gave it a shot. It works great and I really love this huge improvement to the typings story.However the first thing I saw when I ripped out all remaining triple-slash references was a lot of
TS2307: can't find module 'fs'
(and similar) errors for node builtin modules. So I added an explicit triple-slash reference to"node_modules/@types/node/index.d.ts"
and those errors went away.The same thing happened with
mocha
, where the compiler couldn't find'describe'
or'it'
until I added a triple-slash reference tonode_modules/@types/mocha/index.d.ts
.I guess this is the expected behaviour, since these are ambient typings. But in the case of the very widely-used
node.d.ts
typings, is there a shortcut so I can justnpm install @types/node
and thenimport * as fs from 'fs'
?Otherwise I hope this caveat will be clearly documented when 2.0 rolls out, since adding the explicit refs to
"node_modules/@types/node/index.d.ts"
is not the most obvious thing given the new 'automatic' lookup system.The text was updated successfully, but these errors were encountered: