TypeScript settings not picked up by editor, but works on command line/terminal

575 Views Asked by At

I'm trying to work on this TypeScript project. I've written a tsconfig.json, and when I try running from the command line, everything works fine.

However, when I try editing the project's files in Visual Studio Code, Visual Studio, Sublime, or WebStorm, those settings don't appear to be getting applied. Here's a few things that are special about this tsconfig.json in case it helps:

  • It uses the strict flag.
  • It uses noImplicitAny and strictNullChecks for good measure.
  • It uses path mapping (i.e. the paths and baseUrl fields).

How can I get this working?

1

There are 1 best solutions below

0
On

First: make sure your tsconfig.json is free of syntax errors

You might add a field to your configuration file, but JSON is a very picky language, so while you may have previously run with tsc, you might not have noticed your tsconfig.json was recently broken.

Second: make sure that your files are being included in the project configuration

First, check that your tsconfig.json is including your files by running tsc using the --listFiles flag.

If the files are not listed by tsc --listFiles, you can add them to your tsconfig.json using a set of top-level fields:


The include & exclude fields

The easiest way is to specify a series of patterns (specifically "globs") to match folders & files using the "include" and "exclude" fields. This can be an entire folder like ./src.

For example:

{
    "compilerOptions": {/*...*/},
    "include": ["./src"]
}

The files field

You can specify the list of files using the "files" field. If you have a single file that transitively imports everything else, then you can just list that entry-point. But make sure you end up actually importing those files.

For example:

{
    "compilerOptions": {/*...*/},
    "files": ["./src/index.ts"]
}