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
When the initial state is "green", the on transition values inside green are incorrectly limited to "green". However, for the other states (yellow and red), TypeScript correctly allows all state keys. This behaviour follows with the value that is set within initial
for other values, it shows all suggestions:
π Expected behavior
The suggestions should include all values ('green', 'yellow' and 'red') not just the value that is set to initial,
Additional information about the issue
Note: This is not a bug with typescript type resolution, if you provide the value 'red' for example, it will not throw an error, but if you provide a value that is not a key in state (eg: 'foo') it will throw an error (this works as it should), this is merely a bug with the options typehint provides.
The text was updated successfully, but these errors were encountered:
It's weird; it looks like the issue is inside states[k] when initial is k. So if you make it "red" then the red object has the issue (which is at least less insane than something specific to the string literal "green"). Anyway, barring a change or fix, I'd probably work around this by making initial's type NoInfer<keyof T> or something.;
A fix for this is already pending for quite a bit here: #56182 . You can even see almost the same example of this behavior in one of the test cases I have added there, see here. I have also explained there why this happens (implementation-wise).
π Search Terms
"auto complete", "type hint" "inference"
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAysCGwIB4AqUIA8kDsAmAzlAEoQDGA9gE57IHBUCWOA5gDRTw4gB8HACvCoQcwDNhGFO3HlAC8UAN4AoKFGaNgjeABsA-AC4oAawggKAMyioA3MtVR6iCAUNQAci6R44zgLLwZAAWzBAwwRAAtvBoPHYOFDhuilAA2gDS6jiODMwsALpGpuZWgsKiUAA+UACu+BAWoXhQAL52bfagkB5eED4ISAHBoeFBUTHoWLhSpJQ0dLmsHFy8sgoqahlZJmaW1oWwAyioGfkcqHHKHcoWdWRaiVBkws6o4H1DITjH4tNEs9RaPQmEtpKsABSUHCNFhGXxINAcYp7C4ASiUDmEwBqVGyUJh7Xsyih9Cg0WG33kTxeSDekDwn1C4I2WU02h0RgARCxhCJOWwHE4kAQjCy1DyICJRQ41GpEtLZYrrABJPwAUWIXIlfIFStl-AA8gB1DUAfQNAFVUABBADiaq5wjw-JlSoAYgbiAAhZUAEV9avcprVADVA6gjHU8A0mq61C1XS1dbKQBAdDoKAB3BVK+UYvVqVCqjWOvougtQQ0m4jmq12h1QTlOzlx1qJ5NqJ05xV5sVKovqzWN7U4csFqtmy02+2l52tpOJhwJlqouxAA
π» Code
π Actual behavior
When the initial state is "green", the on transition values inside green are incorrectly limited to "green". However, for the other states (yellow and red), TypeScript correctly allows all state keys. This behaviour follows with the value that is set within
initial
for other values, it shows all suggestions:
π Expected behavior
The suggestions should include all values ('green', 'yellow' and 'red') not just the value that is set to
initial
,Additional information about the issue
Note: This is not a bug with typescript type resolution, if you provide the value 'red' for example, it will not throw an error, but if you provide a value that is not a key in state (eg: 'foo') it will throw an error (this works as it should), this is merely a bug with the options typehint provides.
The text was updated successfully, but these errors were encountered: