【发布时间】:2019-06-27 15:20:02
【问题描述】:
我想在将来使用 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,以防未来)?
这是我当前的 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"
]
}
【问题讨论】:
-
如果您想使用 .js 文件而不使用任何类型,或者如果您想使用 .ts 文件并在使用过程中慢慢引入类型,这个问题会很困惑。如果是后者,那么您最好的选择是
TSC_COMPILE_ON_ERRORenv 变量中投票率最低的答案之一
标签: javascript reactjs typescript