TypeScript Version:
3.9.0-dev.20200315
Search Terms:
- object property preserve unique symbol
- module.exports preserve unique symbol
Code
// @target: ES2015
// @module: CommonJS
// @allowJs
// @checkJs
// @noEmit
// @filename: index.js
const customSymbol = Symbol("custom");
// ^?
// This is a common pattern in Node’s built-in modules:
module.exports = {
customSymbol,
// ^?
};
Workbench Repro
Also, the following requires a // @ts‑ignore comment, but otherwise works:
// some-module.js
const customSymbol = Symbol("custom");
// This is a common pattern in Node’s built-in modules:
module.exports = {
/** @type {typeof customSymbol} */
// @ts-ignore
customSymbol,
// ~~~~~~~~~~~~ TS2322: Type 'symbol' is not assignable to type 'unique symbol'.
};
Expected behavior:
// some-module.d.ts
declare const customSymbol: unique symbol;
declare const _default: {
customSymbol: typeof customSymbol;
};
export = _default;
Actual behavior:
// some-module.d.ts
declare const _default: {
customSymbol: symbol;
};
export = _default;
Playground Link:
https://www.typescriptlang.org/play?module=1#code/MYewdgzgLgBMCu0QFsDKBPZAjEAbGAvDBtngBQBECSyFAlANwCwAUAKYAeADiAE6xEA3qxii4iKChI5cAGlYBfZiyA
Related Issues:
TypeScript Version:
3.9.0-dev.20200315Search Terms:
Code
Workbench Repro
Also, the following requires a
// @ts‑ignorecomment, but otherwise works:Expected behavior:
Actual behavior:
Playground Link:
https://www.typescriptlang.org/play?module=1#code/MYewdgzgLgBMCu0QFsDKBPZAjEAbGAvDBtngBQBECSyFAlANwCwAUAKYAeADiAE6xEA3qxii4iKChI5cAGlYBfZiyA
Related Issues:
module.exports#37404