You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeAxes="x"|"y"|"z";constAxes={X: "x",// Not X: "x" as AxesY: "y",Z: "z"}functiontest(axes: Axes){}test(Axes.X);// Argument of type 'string' is not assignable to parameter of type 'Axes'.
Expected behavior:
No error Actual behavior:
Assignability error
Since Axes is declared as a const, I expect the type inference to resolve Axes.X to "x" without the need for "as Axes".
The text was updated successfully, but these errors were encountered:
Axes is const, so someone can't do Axes = .., but the properties of the object referred to be Axes are still mutable, so someone could do Axes.X = "foo", which is allowed since TypeScript inferred the X property to be of type string, not "x".
There's probably a few ways to do what you want. Here's one:
TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
Code
Expected behavior:
No error
Actual behavior:
Assignability error
Since
Axes
is declared as aconst
, I expect the type inference to resolveAxes.X
to"x"
without the need for "as Axes".The text was updated successfully, but these errors were encountered: