-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Literal number types of static readonly members break in declaration files. #17940
Comments
this is a design limitation. type aliases are really just that, aliases. the declaration emitter tries to its best abilities to maintain these, but there is a limit to that. |
@mhegazy I don't entirely get your explanation. The issue is that while the types of (Sorry if I made the issue unnecessarily complex with the discriminated union I was trying t give an example of where this is an issue.) |
Yes, reducing it to a clearer item is that, at authoring time: class A {
static readonly FOO = 1;
} results in When a declaration is emitted it becomes: class A {
static readonly FOO: number;
} Which feels more like an issue in that the same type inference is not being made when the declaration file is generated. Of course a work around is to simply assert the typings: class A {
static readonly FOO: 1 = 1;
} And the emitted declaration file will be correct. |
sorry, my bad. i thought the issue was type alias written as a literal type. this issue is already tracked by #15881 |
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed. |
TypeScript Version: 2.4.2 and 2.5.1
Code
Expected behavior:
This works as expected as-is, but if the test function is in a separate package it should work too.
Actual behavior:
In the generated .d.ts, the types of FOO and BAR are
number
, instead of1
and2
respectively. This breaks the discriminated union when it is used in a separate package which only references the .d.ts.Workaround: When specifying the types of FOO and BAR explicitly, they are propagated correctly to the .d.ts.
The text was updated successfully, but these errors were encountered: