running tsc command does nothing, ignores tsconfig file?

Viewed 4146

I have added typescript to my project and have created a tsconfig.json. I wasn't planning on changing all the .js files to .ts files yet, so I put allowJS to true in the tsconfig.

But When I run tsc it does nothing. tsc -p . also does nothing. tsc --version is 3.8.3. In the end I decided to run it on a single file:

tsc src/index.js
error TS6504: File 'src/index.js' is a JavaScript file. Did you mean to enable the 'allowJs' option?

So it looks like it's not seeing the tsconfig file at all? What am I doing wrong? I'm on windows.

1 Answers

Yes tsc ignores your tsconfig.json because you have passed it a file to process.

Typescript docs:

When input files are specified on the command line, tsconfig.json files are ignored.

https://www.typescriptlang.org/docs/handbook/tsconfig-json.html

Use the "include" or "files" keys in your tsconfig.json.

{
    "compilerOptions": {
        "allowJs": true,
        "outDir": "dist"

    },
    "files": [
        "src/index.js"
    ]
}

Now run tsc and a the compiler will create a new directory dist with your index.js file.

Related