Closed
Description
TypeScript Version: 4.0.0-dev.20200508
Search Terms:
importsNotUsedAsValues
import eliding
Code
In TypeScript 3.8, a new importsNotUsedAsValues
feature/compilerOption was added. This, however is producing different output based on if the file is .ts
or .js
.
tsconfig.json
{
"compilerOptions": {
"allowJs": true,
"noResolve": true,
"importsNotUsedAsValues": "preserve",
"target": "ES2015",
"outDir": "./out",
"types": []
}
}
test.js
// @ts-nocheck
import * as moment from 'moment';
import rollupMoment__default from 'moment';
export const moment = rollupMoment__default || moment;
Output
// @ts-nocheck
import * as moment from 'moment';
import 'moment';
export const moment = rollupMoment__default || moment;
Removing the importsNotUsedAsValues
option, which is equivalent of having the value of remove
will produce:
// @ts-nocheck
import * as moment from 'moment';
export const moment = rollupMoment__default || moment;
Changing the file extension from .js
to .ts
will produce the correct output for both cases
// @ts-nocheck
import * as moment from 'moment';
import rollupMoment__default from 'moment';
export const moment = rollupMoment__default || moment;
Expected behavior:
- Used imports are not elided.
- Given the same input it should produce the same output, irrespective of the file extension.
Actual behavior:
- Given a JS input the import is elided incorrectly.
Playground Link: Playground doesn't have the importsNotUsedAsValues
options.
Related Issues: None that I can find.