TIM*_*MEX 10 javascript typescript reactjs
我想将来使用TypeScript ,但是现在,我选择在Create React App中安装TypeScript.(稍后,我会回去添加类型)
因此,我想禁用所有类型检查.
现在,当我做这样的事情时:
<PlaceSearchBar
placeSearchChanged={this.placeSearchChanged}
/>
class PlaceSearchBar extends React.Component {
...
}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
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
Run Code Online (Sandbox Code Playgroud)
显然我需要声明类型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"
]
}
Run Code Online (Sandbox Code Playgroud)
小智 21
没有类型的Typescript是Javascript.在没有Typescript的情况下启动项目,并在准备好时将其转换.从一开始<any>
就不是一个好习惯,在我看来毫无意义.
Kar*_*ski 18
将此添加到您的tsconfig.json
:
{
"compilerOptions": {
...
"checkJs": false
...
}
}
Run Code Online (Sandbox Code Playgroud)
并坚持.js
/ .jsx
文件现在.只有在准备好使用类型时才使用.ts
/ .tsx
extension.
如果您希望逐行抑制错误,可以使用// @ts-ignore
注释.
我同意 nologin,这样做没有意义,但是如果你真的想要有一些我能想到的方法,这里有几个:
在文件顶部添加此注释 /* tslint:disable */
从 tslint.json 中排除您的代码文件夹(也可能需要在 tsconfig.json 上执行此操作
{
// some linting options
linterOptions: {
exclude: ['src/**','components/**'],
}
}
Run Code Online (Sandbox Code Playgroud)
只需用空对象替换 tslint.json 和 tsconfig.json 文件