In my module A, I have a set of classes, types, and interfaces being exported:
export class Event {
// empty
}
export interface EventHandler {
handle(event: Event): void
}
export type EventCallback = (event: Event) => void
These can be utilized in another module B as shown below:
import {
EventCallback,
EventHandler,
Event
} from "./ts_interface_bug"
let x: EventCallback = (event) => {
console.log(event)
}
class MyHandler implements EventHandler {
handle(event: Event): void {
console.log(event)
}
}
However, when compiling to JavaScript (B.js
), the compiler retains the types:
import { EventCallback, EventHandler, Event } from "./ts_interface_bug.js";
let x = (event) => {
console.log(event);
};
class MyHandler {
handle(event) {
console.log(event);
}
}
This behavior is incorrect - no code for types and interfaces should be generated like in A.js
:
export class Event {
}
Is this a bug, or is there a way to configure the TypeScript compiler to exclude types and interfaces?
TypeScript 3.5.3
tsconfig-build.json
:
"compilerOptions": {
"allowJs": true,
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"strict": true,
"strictPropertyInitialization": false,
"target": "ES2016",
"lib": [
"dom", "ES2016"
],
"module": "ES2015",
"moduleResolution": "node",
"typeRoots": [
"./node_modules/@types"
],
"plugins": [
{
"transform": "@zoltu/typescript-transformer-append-js-extension/output/index.js"
}
],
},
package.json
:
"scripts": {
"build": "ttsc --build tsconfig-build.json",
},
"devDependencies": {
"@zoltu/typescript-transformer-append-js-extension": "^1.0.1",
"ttypescript": "^1.5.7",
"typescript": "^3.5.3"
}