现在有一种更好的方法,无需使用以前的tsd或typings工具。NPM现在拥有typescript的@types软件包。在这个例子中,您需要安装@types/node
软件包:
npm install "@types/node" --save-dev
确保你在使用save-dev选项来仅在开发模式下安装类型,而不是在生产模式下。当你使用npm install "@types/"语法时,你需要有最新的node库...
它找不到fs包,因为之前的工具类型很可能没有使用最新的node.d.ts定义文件。
你的tsconfig.json文件需要更新以找到这些类型包。我的例子使用了jquery、jqueryui和node类型。假设你也需要让这个语法能够在你的代码编辑器中使用,比如'atom'代码编辑器。
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": "src",
"sourceMap": true,
"target": "es5",
"module": "amd",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"lib": ["es2015", "dom"],
"baseUrl": "./",
"typeRoots": [
"node_modules/@types"
],
"types": [
"jquery",
"jqueryui",
"node"
],
"paths": {
"src/*": ["src/*"]
}
},
"exclude": [
"node_modules",
"dist",
"build"
],
"filesGlob": [
"./src/**/*.ts",
"./test/**/*.ts",
"./typings/index.d.ts",
"./custom_typings/**/*.d.ts",
"./node_modules/@types/**/*.d.ts"
],
"atom": {
"rewriteTsconfig": false
}
}
node
执行这段代码吗? - peteb