Closed
Description
Bug Report
preserveValueImports
doesn't error when you import an ambient const enum with isolatedModules
on. Instead you get an error at runtime.
🩹 Proposed Solution
If the named import were a type vs. an ambient const enum, you'd get a compile-time error instead.
#47817 raises that error on ambient const enums, by changing its predicate to include ambient const enums.
🔍 Search Terms
preserveValueImports
ambient const enum
🕗 Version & Regression Information
4.5.0-dev.20210909 - 4.7.0-dev.20220225
⏯️ Playground Link
🧑💻 Code
// @preserveValueImports
// @isolatedModules
import { RoundingMode } from "big.js";
// @filename: node_modules/big.js/index.d.ts
export const enum RoundingMode {}
🙁 Actual Behavior
Runtime error:
import { RoundingMode } from "big.js";
^^^^^^^^^^^^
SyntaxError: Named export 'RoundingMode' not found. The requested module 'big.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'big.js';
const { RoundingMode } = pkg;
🙂 Expected Behavior
Compile-time error (with #47817):
index.ts:1:10 - error TS1446: 'RoundingMode' resolves to a type-only declaration and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
1 import { RoundingMode } from "big.js";
~~~~~~~~~~~~