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

标签 javascript reactjs typescript

以后想使用 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/

相关文章:

javascript - HTML5 WebSQL 优化/缓存选项?

javascript - 使用表数据自定义 React Antd 表头

Reactjs:为什么img的src不能传递给props?

javascript - VS Code 显示模块未找到,即使 WebPack 构建有效

javascript - Angular递归创建动态组件

javascript - 表列大小调整为 100% 容器高度

javascript - RoR GMaps 应用程序中的无效值错误 - 无需更改代码

css - react 和基础 : can't use row class

typescript - 有没有办法使用 typescript 和 Sequelize 向查询添加选项?

javascript - 如何使用 google apps 脚本划掉电子表格的一行(不是删除它!)?