error TS7005: Parameter ‘a‘ implicitly has an ‘any‘ type,TS 类型语义检查报错如何解决?多种方法解决

遇到了 TypeScript 的类型语义检查报错,其实解决也很简单:

方法 1:声明定义类型

例如:

    let arr = $state<number[]>([]);

方法 2:关闭项目 / 编辑器的隐式 any 检查

打开项目下的 jsconfig.json 或 tsconfig.json 文件中添加,例如:

{
    "compilerOptions": {
        "moduleResolution": "bundler",
        "target": "ESNext",
        "module": "ESNext",
        /**
         * svelte-preprocess cannot figure out whether you have
         * a value or a type, so tell TypeScript to enforce using
         * `import type` instead of `import` for Types.
         */
        "verbatimModuleSyntax": true,
        "isolatedModules": true,
        "resolveJsonModule": true,
        /**
         * To have warnings / errors of the Svelte compiler at the
         * correct position, enable source maps by default.
         */
        "sourceMap": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        /**
         * Typecheck JS in `.svelte` and `.js` files by default.
         * Disable this if you'd like to use dynamic types.
         */
        "checkJs": true,
        "noImplicitAny": false
    },
    /**
     * Use global.d.ts instead of compilerOptions.types
     * to avoid limiting type declarations.
     */
    "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值