Let's say I have a file adder.ts
which looks like:
import { Operand } from './operand';
export interface Adder {
add(op1: Operand, op2: Operand): Operand;
}
And my tsconfig.json
looks like:
{
"compilerOptions": {
"declaration": false,
"module": "commonjs",
"outDir": "./dist",
"target": "es6",
"sourceMap": true
},
"include": [
"src/**/*"
]
}
When I transpile this code I would expect to receive only dist/adder.d.ts
. However, there is also a dist/adder.js
generated with the contents:
Object.defineProperty(exports, "__esModule", { value: true });
Why is this file generated? What purpose does it serve? At the end of the day I suppose I don't really care much because it would never actually get required/loaded and will be pruned out by any bundler. The only reason I noticed it was because my coverage tool was reporting this file as uncovered.
Official answer, found by a web search: generating a .js
for every .ts
simplifies build processes.
A side benefit is that if you do something silly like:
import * as Adder from "./dist/adder"; // or whatever is the correct path
console.log(Adder);
you get an empty namespace instead of a runtime error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With