如何禁用所有打字稿类型检查?

问题描述:

我希望将来使用TypeScript ,但是目前,我选择在Create React App中安装TypeScript.(稍后,我将返回并添加类型)

I would like to use TypeScript in the future, but for right now, I have chosen to install TypeScript in Create React App. (Later, I will go back and add types)

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

Therefore, I would like to disable all type checks.

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

Right now, when I do something like this:

<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> 或此类中声明类型.

Apparently I need to declare types in React.Component<placeSearchChanged:function> or something of that sort.

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

I think it's annoying, and I would like to disable all checks in my tsconfig.json.

如何禁用所有检查(但仍安装TypeScript,以确保将来使用)?

How can I disable all checks (but still keep TypeScript installed, just for future-proof)?

这是我当前的tsconfig.json:

This is my current 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 扩展名.

and stick to .js/.jsx files for now. Use the .ts/.tsx extension only when you're ready to use types.

如果您希望逐行消除错误,则可以使用//@ ts-ignore 注释.

If you would rather suppress the errors on a per-line basis, you can use a // @ts-ignore comment.