-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Explain how to configure TypeScript for use on Node.js #213
Comments
I am looking for the same thing. The node @typings can be installed with: npm install @types/node --save The expectation being that it should then be possible to import one of the modules defined for node. import http = require('https'); The basic problem is that '@types/node' is a 'multi-module' definition file, ///<reference path="../../../../node_modules/@types/node/index.d.ts" /> It is my understanding that the same effect can be obtained by adding the reference to the 'tsconfig.json' in the 'files' section (or alternatively in the 'include' section). "include": [
"./src/ts/**/*.ts",
"./node_modules/@types/node/index.d.ts"
], However this does not appear to be not the proper way.
'tsconfig.json' in the 'files' section (or alternatively in the 'include' section). "compilerOptions": {
...
"types": [
"node"
], Can we get some love from the TypeScript team to fact-check my hypothesis? |
have you tried TS 2.0 with the |
@mhegazy |
You should not need to specify |
@mhegazy Right typeRoots is not necessary so I removed it from the comment. But, I think the types is necessary and is not present in the documentation. |
types is not if the tsconfig.json is next to your node_modules. i have filed a bug to fix the issue (microsoft/TypeScript#10617). The compiler does "automatic" inclusion to @types packages; it looks under i am guessing your node_modules is one or more levels higher than your tsconfig.json, and thus it is not being picked up automatically. the other option to include it is either 1. add it to the |
i should add that the intention of the design was not to need to add either. and thus the lack of documentation was under the impression that these references should not be needed, and users do not need to be distracted by them. |
@mhegazy I am also developing .d.ts files for npm packages that I am using for which there is no .d.ts If typeRoots is specified does it replace or add-to the default typeRoots values? |
sure thing.
You should not bundle third-party declarations with your package. these should be published separately.
I am not sure what you mean by that. can you elaborate. |
If I want to add another directory, say @types, and I want the compiler to "typeRoots": [ "node_modules/@types", "@types" ] ...or is 'node_modules/@types' implicitly included? ... "typeRoots": ["@types] Similarly, can 'node_modules/@types' be ignored by... "typeRoots": [ ] No, I have no particular use-case, I am just trying to understand the |
| The compiler does "automatic" inclusion to @types Does the "automatic" inclusion of @types https://github.com/types work by |
it is explicit. so you need to list
if for example, here is a sample config for Definitely Typed: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/types-2.0/abs/tsconfig.json if uses the parent folder as the only typeRoot, and does not look into |
I think that covers it pretty well, thanks. |
@mhegazy link to sample config file is broken as of writing (12 Aug 2017). Do you or someone else have a new link? Thank you! |
@mhegazy , the main issue here is
is this still actual? |
TypeScript is a great language for developing server-side applications that run on Node.js, and for developing IoT applications that run on Node.js on embedded devices.
But getting started is difficult due to the complexity of DefinitelyTyped, TSD (deprecated), Typings, triple-slash references versus package.json versus tsconfig.json versus typings.json, typings/main/ambient/node/index.d.ts, etc.
A new page in the TypeScript Handbook under Project Configuration that explains how to configure TypeScript for use on Node.js would be a big help.
The text was updated successfully, but these errors were encountered: