【发布时间】:2022-02-05 00:23:00
【问题描述】:
TS7006:参数“端口”隐式具有“任何”类型。
constructor(port) {
TS7006:参数“消息”隐式具有“任何”类型。
Emit(message) {
我在这里不知所措,因为其他所有答案都是添加类型“任何”或其他类型。 在这种情况下,端口和消息都分别具有类型、数字和字符串。 请注意,我通常不使用节点/打字稿,所以我不知道配置是否良好。还设置 strict: false 和 noImplicitAny: false 与 Emit() 产生类似的错误
throw new TypeError(${relative(cwd, fileName)}: Emit skipped);
这个错误也来自 .js 文件,所以我猜 tsc 通过了?
export class EventEmitter {
private port: number
constructor(port: number) {
this.port = port
...
}
public Emit(message: string) {
this.io.send(message)
}
package.json 脚本
"start": "cd dashboard && (npm run dev > dashboard.log 2>&1 &) && cd .. && tsc-watch --onSuccess \"npm run watch\"",
"watch": "nodemon --watch './src/*.ts' --exec 'node --experimental-specifier-resolution=node --loader ts-node/esm' src/main.ts",
忽略仪表板部分,它是一些需要并行运行的纤细前端部分。
tsconfig.json
{
"include": [
"src",
"dashboard/src/**/*.d.ts",
"dashboard/src/**/*.js",
"dashboard/src/**/*.ts",
"dashboard/src/**/*.svelte"
],
"compilerOptions": {
"moduleResolution": "node",
"target": "es2018",
"module": "esnext",
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"allowJs": true,
"checkJs": true,
"importsNotUsedAsValues": "error",
"isolatedModules": true,
"resolveJsonModule": true,
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "src",
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"baseUrl": ".",
"paths": {
"*": [
"src/*",
"node_modules/*"
]
},
"esModuleInterop": true,
}
}
【问题讨论】:
标签: node.js typescript