How can I disable all typescript type checking?
Asked Answered
U

8

85

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"
  ]
}
Unwritten answered 3/2, 2019 at 19:33 Comment(2)
Possible duplicate of TypeScript - possible to disable type checking?Teem
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 variableNahuatl
L
90

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.

Liverpudlian answered 7/2, 2019 at 10:32 Comment(4)
Shouldn't it have allowJs, too?Aemia
checkJs is false by default: typescriptlang.org/tsconfig#checkJsUnformed
the comment // @ts-ignore is working. Make sure to add this comment just before the line producing the error.Kareenkarel
This is not working in case application has all TS files not JSCellophane
T
36

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

Tabbitha answered 20/1, 2023 at 6:17 Comment(0)
S
30

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

Skillful answered 4/3, 2020 at 16:30 Comment(4)
The build will run, but the errros will clutter up the console. I would advise to use exclude directive in the tsconfig.jsonThorncombe
I think specifying in "exclude" excludes those files in the final bundle and won't be available to use them in other modules. If the files are only type definition files (.d.ts), then it's fineImprovident
This is the only answer here that worked for me.Besides
Thank you i've been stuck on this due to walletconnect's recommended modal usage with wagmi libraries crapping out due to selectedNetworkId type error. I'm typing the error keyword here, in case someone else comes across this issue.German
P
11

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

Priestess answered 6/2, 2019 at 11:55 Comment(4)
Only the second solution will work. TSLint is not the typescript compiler, and an empty tsconfig will just use the default settings.Transmitter
Yeah the second solution is to bypass the compiler, but likely TIMEX has also installed some linting as well which needs to be bypassed which might be required. Some time ago the empty config files was working, might have been reverted (thankfully)Priestess
the disable by file didn't work. the ts-ignore worked for meRagamuffin
Excluding the src folder might have worked 2019, I don't know, but today this throws the error "TS18003: No inputs were found in config file 'tsconfig.json'." and still doesn't compile. -- My reason to skip TS check temporarily is to evaluate on updating or replacing some very old project. I.e. not to make it compile cleanly, but to check what exactly doesn't work in what way.Stanwood
W
7

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.

Wartime answered 3/2, 2019 at 19:44 Comment(4)
While this answer makes sense in OP's context, it failed to answer the title (which is why I came here). FYI: I was looking for disabling all type checks in a generated client file that contains errors like property not definitely accessed from constructor.Deceitful
The accepted solution is about .js and .ts. That points in the same direction as this post does. Use js and switch to ts when you are ready to do so. @Karol just exposed the tsconfig setting.Wartime
Consider something like this in a Typescript Express controller: ``` // Bind Internal Methods Object.getOwnPropertyNames(ProjectController.prototype) .filter((methodName: string) => methodName !== 'constructor') // @ts-ignore .forEach((method: string) => (this[method] = this[method].bind(this))); ``` Seems like there is no possible way to write this in a way that TS likes it and even allows and compiles it, for these sort of extreme situations I believe that this 'turn off' comment/feature was implemented.Spacesuit
Any competent software engineer is aware of this, there are still reasons, beyond your tiny set of experiences that one might need to disable Typescript errors while prototyping. For example POCing Webpack 5 Module Federation. Minus - 1 for captain obvious boring aloneJacaranda
T
3

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.

Temptation answered 5/12, 2021 at 7:43 Comment(0)
S
1

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

Sunrise answered 7/2, 2019 at 10:8 Comment(0)
S
-1

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

Surly answered 4/8, 2022 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.