admin管理员组

文章数量:1134246

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 {
...
}

I get an error:

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

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

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

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

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"
  ]
}

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 {
...
}

I get an error:

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

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

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

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

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"
  ]
}
Share Improve this question asked Feb 3, 2019 at 19:33 TIMEXTIMEX 271k365 gold badges799 silver badges1.1k bronze badges 2
  • Possible duplicate of TypeScript - possible to disable type checking? – Christophe Commented Nov 23, 2019 at 19:56
  • This question is confused by if you want to use .js files and not use any types or if you want to use .ts files and introduce types slowly as you go. If it's the latter then the your best option is one of the least voted up answers with TSC_COMPILE_ON_ERROR env variable – Michał Gacka Commented Oct 17, 2020 at 16:08
Add a comment  | 

9 Answers 9

Reset to default 92 +150

Add this to your tsconfig.json:

{
  "compilerOptions": {
    ...
    "checkJs": false
    ...
  }
}

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

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

you can use a // @ts-nocheck comment at the top of a file to disable type-checking for that file.
more @ here

You can let the CRA build happen even in presence of typescript errors.

Just set the environment variable TSC_COMPILE_ON_ERROR=true

Check CRA documentation for more detailed information

I agree with nologin, there is no point doing that, however if you really want to there are a few ways that I can think of, here is a couple:

Disable by file

add this comment at the top of the file /* tslint:disable */

Exclude your src folder

Exclude your code folders from tslint.json (might need to do it on tsconfig.json too

{
 // some linting options
  linterOptions: {
    exclude: ['src/**','components/**'],
  }
}

Empty tslint.json and tsconfig

just replace your tslint.json and tsconfig.json files with an empty object

Typescript without types is Javascript. Start your project without Typescript and convert it when you are ready to do so. Beginning with <any> is not a good practice and makes no sense in my opinion.

I was facing the same problem, I tried to modify the tsconfig.json file as follows.

Before:

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
      "baseUrl": "./",
      "outDir": "./dist/out-tsc",
      "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2017",
    "module": "es2020",
    "lib": [
      "es2020",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true
  }
}

After

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
  "compileOnSave": false,
  "compilerOptions": {
      "baseUrl": "./",
      "outDir": "./dist/out-tsc",
      "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitOverride": true,
    "noPropertyAccessFromIndexSignature": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2017",
    "module": "es2020",
    "lib": [
      "es2020",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "enableI18nLegacyMessageIdFormat": false,
    "strictInjectionParameters": false,
    "strictInputAccessModifiers": true,
    "strictTemplates": false
  }
}

changing "strictInjectionParameters": false, and "strictTemplates": false worked for me.

Typescript's USP is type checking at compile time. It ultimately compiles to javascript. Start without typescript. You can always include it in your project when you want to with some refactoring.

https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html

In your tsconfig.json, add "noCheck": true under the "compilerOptions" key

{
  "compilerOptions": {
    // Disable full type checking (only critical parse and emit errors will be reported).
    "noCheck": true
  }
}

https://www.typescriptlang.org/tsconfig/#noCheck

In Angular 14 go to tsconfig.json=> compilerOptions => strict: false

本文标签: javascriptHow can I disable all typescript type checkingStack Overflow