Bug Report
I found the using import Something = Namespace.Something then re-exporting that from a namespace leads to some strange behaviour, but only when import alises are the only things exported.
🔎 Search Terms
"Cannot use namespace" as value
🕗 Version & Regression Information
- This probably has existed for a while
- Tested in 5.2.0-dev.20230529
⏯ Playground Link
https://www.typescriptlang.org/play?ssl=24&ssc=86&pln=2&pc=3#code/CYUwxgNghgTiAEBbA9sArhBAXEBnL8A3gLABQ8SqGCADlGANYCMRZFFYyAdvvDvkwBc8fDACWXAOYBuNu048C-LAGZhXNIgBGIGLPLsQADxrIYBQnzxYmAGiv4V8AL76KzuSnSZ4dRgCZWAwoxRFNzBxt4AF5femYAOmUmN3ZQ8KVrJ1i-ROUVVIpjDKJIu0inVzkPAy9qOMYnEmD4dLNMgRiGhn8k6xS5ELD2iq7c3vzC+GKRy2T7fJdUmrk2iNyAURN2lhz4pj6BVLWCTe3zQL2Aw5tj4fX4rYzs7pUbgYMT7qf2gBYx+ITfr6OQKXj5YRYACeNBAyAAZt9zqpUjMIpYzhkWFBcGV7Jj2oEcZF-AssvjHsj-sTlP8qqRnEA
💻 Code
declare module pack1 {
const test1: string;
const test3: number;
export { test1, test3 };
}
declare module pack2 {
import test1 = pack1.test1;
import test3 = pack1.test3;
export { test1, test3 };
}
declare module pack3 {
import test1 = pack2.test1;
import test3 = pack2.test3;
export { test1, test3 };
}
import packExport1 = pack1.test1;
import packExport2 = pack2.test1;
import packExport3 = pack3.test1;
import packExport4 = pack2.test1;
declare const test3: typeof packExport3;
export { packExport1 as test1, packExport2 as test2, test3, packExport4 as test4 };
🙁 Actual behavior
The types are inferred correctly, but the type checker errors:
> npx tsc test.d.ts
test.d.ts:12:18 - error TS2708: Cannot use namespace 'pack2' as a value.
12 import test1 = pack2.test1;
~~~~~
test.d.ts:13:18 - error TS2708: Cannot use namespace 'pack2' as a value.
13 import test3 = pack2.test3;
~~~~~
test.d.ts:18:22 - error TS2708: Cannot use namespace 'pack2' as a value.
18 import packExport2 = pack2.test1;
~~~~~
Found 3 errors in the same file, starting at: test.d.ts:12
🙂 Expected behavior
No errors.
Workaround
Add some other declaration and export it from any namespace that only exports import aliases:
// no diagnostics, everything is fine now
declare namespace pack1 {
const test1: string;
const test3: number;
export { test1, test3 };
}
declare namespace pack2 {
import test1 = pack1.test1;
import test3 = pack1.test3;
export const __dummyExport: string; // edit: actually, i discovered this doesn't need to be exported
export { test1, test3 };
}
declare namespace pack3 {
import test1 = pack2.test1;
import test3 = pack2.test3;
export const __dummyExport: string;
export { test1, test3 };
}
import packExport1 = pack1.test1;
import packExport2 = pack2.test1;
import packExport3 = pack3.test1;
import packExport4 = pack3.test3;
declare const test3: typeof packExport3;
export { packExport1 as test1, packExport2 as test2, test3, packExport4 as test4 };
Workaround 2
Use export import:
// no errors
declare namespace pack1 {
const test1: string;
const test3: number;
export { test1, test3 };
}
declare namespace pack2 {
export import test1 = pack1.test1;
export import test3 = pack1.test3;
}
declare namespace pack3 {
export import test1 = pack2.test1;
export import test3 = pack2.test3;
}
import packExport1 = pack1.test1;
import packExport2 = pack2.test1;
import packExport3 = pack3.test1;
import packExport4 = pack3.test3;
declare const test3: typeof packExport3;
export { packExport1 as test1, packExport2 as test2, test3, packExport4 as test4 };
Bug Report
I found the using
import Something = Namespace.Somethingthen re-exporting that from a namespace leads to some strange behaviour, but only when import alises are the only things exported.🔎 Search Terms
"Cannot use namespace" as value
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?ssl=24&ssc=86&pln=2&pc=3#code/CYUwxgNghgTiAEBbA9sArhBAXEBnL8A3gLABQ8SqGCADlGANYCMRZFFYyAdvvDvkwBc8fDACWXAOYBuNu048C-LAGZhXNIgBGIGLPLsQADxrIYBQnzxYmAGiv4V8AL76KzuSnSZ4dRgCZWAwoxRFNzBxt4AF5femYAOmUmN3ZQ8KVrJ1i-ROUVVIpjDKJIu0inVzkPAy9qOMYnEmD4dLNMgRiGhn8k6xS5ELD2iq7c3vzC+GKRy2T7fJdUmrk2iNyAURN2lhz4pj6BVLWCTe3zQL2Aw5tj4fX4rYzs7pUbgYMT7qf2gBYx+ITfr6OQKXj5YRYACeNBAyAAZt9zqpUjMIpYzhkWFBcGV7Jj2oEcZF-AssvjHsj-sTlP8qqRnEA
💻 Code
🙁 Actual behavior
The types are inferred correctly, but the type checker errors:
🙂 Expected behavior
No errors.
Workaround
Add some other declaration and export it from any namespace that only exports import aliases:
Workaround 2
Use
export import: