【问题标题】:Q: Typescript: TS7006: Parameter implicity has any type问:打字稿:TS7006:参数隐含任何类型
【发布时间】: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


    【解决方案1】:

    答案是设置checkJS: falseallowJS: false 如果这是错误的并且有人知道更好,请告诉我。 谢谢。

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2017-08-21
    • 2021-11-17
    • 1970-01-01
    • 2023-03-08
    • 2020-02-02
    • 2018-08-15
    • 2021-03-29
    • 2018-11-30
    • 1970-01-01
    相关资源
    最近更新 更多