我想在将来使用TypeScript,但是现在,我选择在中安装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安装,只是为了将来的证明)?
这是我现在的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"
]
}
发布于 2019-02-07 10:32:20
将此添加到tsconfig.json
中
{
"compilerOptions": {
...
"checkJs": false
...
}
}
现在继续使用.js
/.jsx
文件。仅在准备使用类型时才使用.ts
/.tsx
扩展。
如果您希望以一行为基础来抑制错误,可以使用// @ts-ignore
注释。
发布于 2020-03-04 16:30:49
发布于 2019-02-03 19:44:25
没有类型的类型记录是Javascript。在没有打字本的情况下启动项目,并在准备好时进行转换。从<any>
开始并不是一个好的实践,在我看来没有任何意义。
https://stackoverflow.com/questions/54506744
复制相似问题