Closed
Description
TypeScript Version: 3.1.0-dev.20180726
Search Terms:
enum literals declarations
Code
enum E {
A = 'a',
B = 'b'
}
class C {
readonly type = E.A;
}
let x: E.A = new C().type; // no error, type is inferred to E.A, not E.
Expected behavior:
I expect similarly the .d.ts emitted to have a narrowed declaration for 'type'
declare class C {
readonly type: E.A;
}
Actual behavior:
Emitted .d.ts contains:
declare class C {
readonly type: E;
}
Note this is critical for creating tagged unions for type narrowing, and this behavior makes type narrowing only work when one is not crossing a '.d.ts' boundary. Bazel compliations usually look like 2-3 .ts files and hundreds to thousands .d.ts files from downstream compilations.
Related Issues: