Closed CarsonF closed 4 months ago
This all makes sense, but my curiosity wants to know a real life example of where this will be handy in our codebase? Or are you optimizing for the future here?
PR incoming for Workflow, which will have a state enum, typed generically.
Two changes to make this compatible.
First, disallow direct access to member values when referencing generically.
Without this change
Color
can't be assigned toAnEnum
, because the TS defines the member values as an index:{ [x: string]: string }
. So since one has an index accessor and one doesn't, making them incompatible.Secondly, The
entry()
arg type change also allows them to be compatible. Without it TS thinks something likeentry()
fn accepting anystring
is not compatible withentry()
fn only accepting'red' | 'blue'
. Using another generic at the function level somehow works around this, while still maintaining all the strictness.