Node.js ts节点忽略自定义类型声明
问题就如主题所述。有趣的事情-我有另一个项目,配置和类型非常相似,在那里工作得很好 package.jsonNode.js ts节点忽略自定义类型声明,node.js,typescript,ecmascript-6,ts-node,Node.js,Typescript,Ecmascript 6,Ts Node,问题就如主题所述。有趣的事情-我有另一个项目,配置和类型非常相似,在那里工作得很好 package.json { "name": "untitled", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "ts-node test
{
"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"
}
}
{
"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"]
}
tsconfig.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"
}
}
{
"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
polyfills.ts
这些错误。
请帮忙:)
更新:
tsc&&node build/test.js
工作正常您在问题中发布的示例不会产生错误。是否应该有一个附加文件,如test.ts
?由于错误在polyfills.ts中,您应该在问题中包含该代码test.ts
中唯一相关的信息是import./polyfills'代码>作为第一个字符串polyfills
本身与prob无关-它不起作用,因为找不到定义。
Array.prototype.random = function () {
return this[Math.floor((Math.random()*this.length))];
};