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
|
9 Answers
Reset to default 92 +150Add 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
版权声明:本文标题:javascript - How can I disable all typescript type checking? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736843008a1955182.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
TSC_COMPILE_ON_ERROR
env variable – Michał Gacka Commented Oct 17, 2020 at 16:08