Typescript: force exclude file even if it was imported

Viewed 336

I want to exclude a *.ts file from compilation by adding it into "exclude" property in tsconfig.json. Although if I do import that file somewhere in the code it ignores the exclusion and compiles it anyway. How to force TS to exclude this file?

../

../must_be_excluded.ts

../index.ts

Using import

//index.ts
import {some_stuff} from "./must_be_excluded"

Tsconfig settings

//tsconfig.json
{
   "compilerOptions": {...},
   "exclude": ["./must_be_excluded.ts"]
}

I see must_be_excluded.js anyway!

1 Answers

Well it'll have to be, if you're importing and using that function in anywhere that needs it, it'll need to be compiled into JavaScript.

How would it work otherwise? Everything will run smoothly until that particular function call.

Try removing the import declaration and you'll notice it should respect the fact it's excluded.

Related