Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"   ] } 
like image 923
TIMEX Avatar asked Feb 03 '19 19:02

TIMEX


People also ask

How do I get rid of TypeScript errors?

Use // @ts-ignore to ignore the type checking errors on the next line in a TypeScript file. If you use a linter, you might have to add a comment to also suppress linting errors when using ts-ignore - // eslint-disable-next-line @typescript-eslint/ban-ts-comment . Copied!

How do I disable TypeScript in a project?

You could go to Tools > Options > Text Editor > JavaScript/TypeScript > Project and uncheck the Project Analysis options.

How do I disable TypeScript for a specific file?

Use the // @ts-nocheck comment to disable type checking for an entire file in TypeScript. The // @ts-nocheck comment instructs TypeScript to skip the file when type checking. If you use a linter, you might need to disable it on the line of the comment. Copied!

What is TypeScript type checking?

TypeScript type check is used to validate the type of any variable at runtime. Type checking has proven to be a good feature for most JavaScript developers. We will start with the most basic library provided by TypeScript, which will directly validate the type of single variables in the code.


2 Answers

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.

like image 118
Karol Majewski Avatar answered Sep 19 '22 01:09

Karol Majewski


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.

like image 24
nologin Avatar answered Sep 20 '22 01:09

nologin