问题正如主题所述。有趣的事情 - 我有另一个项目,它的配置和类型非常相似,在那里运行良好。
包.json
{
"name": "untitled",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "ts-node test.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@types/node": "^12.0.4",
"fs": "0.0.1-security",
"jszip": "^3.2.1",
"ts-node": "^8.2.0",
"typescript": "^3.5.1"
}
}
tsconfig.json
{
"compilerOptions": {
"lib": [
"es6",
"dom"
],
"typeRoots" : [
"./node_modules/@types",
"."
],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": false
},
"exclude": [
"node_modules",
"**/*.spec.ts",
"**/*.test.ts"]
}
索引.d.ts
declare interface Array<T> {
random() :T;
}
declare namespace NodeJS {
export interface Global {
__stack: any;
__line: any;
__function: any;
sleep: Function;
}
}
这是一个用于测试目的的简单项目 -index.d.ts
也位于项目的根目录中(试图移动index.d.ts
-> typings/index.d.ts
)(当然tsconfig.json
也有新路径)。
每次尝试都以
TSError: ⨯ Unable to compile TypeScript:
polyfills.ts:1:17 - error TS2339: Property 'random' does not exist on type 'any[]'.
polyfills.ts
Array.prototype.random = function () {
return this[Math.floor((Math.random()*this.length))];
};
这些错误。请帮忙 :)
更新:
tsc && node build/test.js
工作正常