Typescript Troubleshooting

Skip type-checking

Certain edge cases may force you to skip type-checking. The following lists the different ways a code line, file, component, or package, can be ignored by Typescript's type-checking.

Use JS extension

Typescript is set, by default, to allow for JS files ("allowJs": true) in your components, but to skip type-checking in those files ("checkJs": false). These default configurations can be utilized to ignore an entire file as well as its dependencies.

For example:

// @filename: my-component.js

// this dependency will, not be type-checked
import mongoose from 'mongoose';

// this will not be type-checked
mongoose
  .connect('mongodb://127.0.0.1:27017/test')
  .then(() => console.log('Connected!'));
CopiedCopy

Inline ignore comments

Inline 'ignore' comments can also be used to ignore type-checking.

The following skips type-checking of specific lines of code:

/* @ts-ignore */
import mongoose from 'mongoose';

/* @ts-ignore */
mongoose
  .connect('mongodb://127.0.0.1:27017/test')
  .then(() => console.log('Connected!'));
CopiedCopy

The following skips type-checking of the entire file:

/* @ts-nocheck */

import mongoose from 'mongoose';

mongoose
  .connect('mongodb://127.0.0.1:27017/test')
  .then(() => console.log('Connected!'));
CopiedCopy

Skip checking of declaration files

Set your Typescript configuration to skip the type-checking of deceleration any file that is not specifically referred to by your components.

// @filename: my-env/config/tsconfig.json
{
  "extends": "@teambit/react.react-env/config/tsconfig.json",
  "include": ["**/*", "**/*.json"],
  "compilerOptions": {
    "skipLibCheck": true
  }
}
CopiedCopy

To learn more see Typescript's official documentation.