source

모든 타입 스크립트유형 체크를 비활성화하려면 어떻게 해야 하나요?

nicesource 2023. 2. 14. 21:30
반응형

모든 타입 스크립트유형 체크를 비활성화하려면 어떻게 해야 하나요?

향후 TypeScript를 사용하고 싶습니다만, 현시점에서는 Create React App에 TypeScript를 인스톨 하는 것을 선택했습니다(나중에 다시 Type을 추가합니다).

따라서 모든 타입 체크를 무효로 하고 싶습니다.

지금 내가 이런 일을 할 때:

<PlaceSearchBar
    placeSearchChanged={this.placeSearchChanged}
/>


class PlaceSearchBar extends React.Component {
...
}

에러가 표시된다.

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

보아하니, 나는 내 타입을 신고해야 할 것 같다.React.Component<placeSearchChanged:function>뭐 그런 거라도요

귀찮은 것 같아서 모든 체크를 무효로 하고 싶습니다.tsconfig.json.

모든 체크를 비활성화하려면 어떻게 해야 합니까(미래에 대비하기 위해 TypeScript를 계속 설치).

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

이 항목을 에 추가합니다.tsconfig.json:

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

에 충실하다.js/.jsx파일을 참조해 주세요.를 사용합니다..ts/.tsx유형을 사용할 준비가 되었을 때만 확장자를 사용할 수 있습니다.

에러를 행 단위로 억제하는 경우는,// @ts-ignore댓글.

타입 스크립트 에러가 있는 경우에서도, CRA 빌드를 실행할 수 있습니다.

환경변수를 설정하기만 하면 됩니다.TSC_COMPILE_ON_ERROR=true

상세한 것에 대하여는, CRA 의 메뉴얼을 참조해 주세요.

타입이 없는 타입 스크립트는 Javascript 입니다.Typescript 없이 프로젝트를 시작하고 변환할 준비가 되면 변환하십시오.처음에<any>좋은 방법이 아니고 내 생각에는 말이 안 된다.

nologin에는 동의하지만, 그렇게 하는 것은 의미가 없습니다만, 만약 당신이 정말로 내가 생각할 수 있는 몇 가지 방법이 있다면, 여기 몇 가지가 있습니다.

파일로 사용 안 함

파일 상단에 이 코멘트를 추가하다/* tslint:disable */

src 폴더 제외

코드 폴더를 tslint.json에서 제외합니다(tsconfig.json에서도 이 작업이 필요할 수 있습니다).

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

tslint.json 및 tsconfig를 비웁니다.

tslint.json 및 tsconfig.json 파일을 빈 개체로 바꾸기만 하면 됩니다.

를 사용할 수 있습니다.// @ts-nocheck파일 맨 위에 있는 주석을 눌러 해당 파일의 유형 검사를 비활성화합니다.
더 @여기에

Typescript의 USP는 컴파일 시 유형 검사입니다.최종적으로 javascript로 컴파일 됩니다.타이프 스크립트 없이 시작합니다.리팩터링을 원할 때 언제든지 프로젝트에 포함할 수 있습니다.

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

저도 같은 문제에 직면해 있었어요.tsconfig.json다음과 같이 파일링 합니다.

이전:

/* 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
  }
}

끝나고

/* 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
  }
}

변화하는"strictInjectionParameters": false,그리고."strictTemplates": false날 위해 일했어

Angular 14에서 tsconfig.json=> 컴파일러 옵션=> strict: false로 이동합니다.

언급URL : https://stackoverflow.com/questions/54506744/how-can-i-disable-all-typescript-type-checking

반응형