Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
137 views
in Technique[技术] by (71.8m points)

javascript - 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"
  ]
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...