gpt4 book ai didi

javascript - 如何禁用所有 typescript 类型检查?

转载 作者:可可西里 更新时间:2023-11-01 02:28:49 24 4
gpt4 key购买 nike

以后想使用 TypeScript,但现在,我选择在 Create React App 中安装 TypeScript。 (稍后我会回去添加类型)

因此,我想禁用所有类型检查。

现在,当我做这样的事情时:

<PlaceSearchBar
placeSearchChanged={this.placeSearchChanged}
/>


class PlaceSearchBar extends React.Component {
...
}

我得到一个错误:

Type error: Type '{ placeSearchChanged: (place: any) => void; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<PlaceSearchBar> & Readonly<{ children?: ReactNode; }> & Readonly<{}>'.
Property 'placeSearchChanged' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<PlaceSearchBar> & Readonly<{ children?: ReactNode; }> & Readonly<{}>'. TS2322

显然我需要在 React.Component<placeSearchChanged:function> 中声明类型或类似的东西。

我觉得这很烦人,我想禁用我的 tsconfig.json 中的所有检查.

我如何禁用所有检查(但仍保持安装 TypeScript,只是为了面向 future )?

这是我当前的 tsconfig.json:

{
"compilerOptions": {
"target": "es6",
"lib": [
"dom",
"dom.iterable",
"esnext",
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"noImplicitAny": false,
},
"include": [
"src"
]
}

最佳答案

将此添加到您的 tsconfig.json:

{
"compilerOptions": {
...
"checkJs": false
...
}
}

现在坚持使用 .js/.jsx 文件。仅当您准备好使用类型时才使用 .ts/.tsx 扩展名。

如果您希望逐行抑制错误,您可以使用 //@ts-ignore 注释。

关于javascript - 如何禁用所有 typescript 类型检查?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54506744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com