TypeScript: tsc -w does not correctly compile file imports
When running tsc -w
, the compiler is incorrectly removing certain module imports. It would appear this bug happens when the imported module’s only usage is in a promise
. If used outside of the promise, the compiler does import the file correctly. This only happens when running the compiler in watch mode.
TypeScript Version: 2.7.0-dev.201xxxxx
Search Terms: tsc tsc-w import missing promise
Code
import * as MyService from '../service/MyService';
export function find() {
return new Promise((resolve, reject) => {
MyService.find()
})
}
Expected tsc output:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const MyService = require("../service/MyService");
function find() {
return new Promise((resolve, reject) => {
MyService.findNext();
});
}
exports.find = find;
Actual tsc output:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function find() {
return new Promise((resolve, reject) => {
MyService.findNext();
});
}
exports.find = find;
Playground Link: Cant really replicate here because I can’t import from disk
Related Issues: none that I’ve found
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 7
- Comments: 22 (21 by maintainers)
Also encountered this in TS@2.7.1
First pass is compiled correctly. Second pass is missing some imports.
This is the source file: https://github.com/unional/komondor/blob/ts-2.7-compile-error/src/spec.ts
In first pass, line 45-52:
Second pass (after making some change elsewhere):
First pass full content:
Second pass full content: