TIMEX
TIMEX

Reputation: 271934

How can I disable all typescript type checking?

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

Upvotes: 89

Views: 222002

Answers (9)

user7610
user7610

Reputation: 28811

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

Upvotes: 1

Alok Raj
Alok Raj

Reputation: 538

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

Upvotes: 46

Khadija Mehmood
Khadija Mehmood

Reputation: 25

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

Upvotes: -1

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.

Upvotes: 3

gobien
gobien

Reputation: 537

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

Upvotes: 31

Karol Majewski
Karol Majewski

Reputation: 25800

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.

Upvotes: 92

Harshit Juneja
Harshit Juneja

Reputation: 385

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

Upvotes: 1

nologin
nologin

Reputation: 1442

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.

Upvotes: 7

Dave
Dave

Reputation: 633

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

Upvotes: 12

Related Questions