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
constfunc1=(arg: Record<'field',string>)=>{}typeType1=Record<'field',string>constfunc2=(arg: Type1)=>{}constarg: Record<string,string>={}func1(arg)// okfunc2(arg)// Property 'field' is missing in type 'Record<string, string>' but required in type 'Type1'.
π Actual behavior
Type alias Type1 differs from original type Record<'field', string>
π Expected behavior
Types of func1 and func2 should be equal and behave the same way, as it worked on 4.1.5 and earlier
The text was updated successfully, but these errors were encountered:
The direct cause of this issue is #42284. We now preserve the alias for Type1 and thus when relating to Record<'field', string> we are no longer relating instantiations of the same type alias. Therefore we relate the types structurally and we discover they're not compatible. The reason we view Record<'field', string> and Record<string, string> as compatible has to do with the way we measure variance. We find that the first type parameter is contra-variant when in reality variance is strictly speaking unmeasurable for mapped types because a string key turns into an index signature which doesn't exactly behave as an infinite number of properties.
I'm pretty sure we already have a bug for this, but haven't been able to find it yet.
I should add, I think we already tried marking variance of mapped types as unmeasurable, but it lead to an explosion in structural type comparisons with significant effects on performance.
Bug Report
π Search Terms
4.2 Type alias
π Version & Regression Information
β― Playground Link
Playground link
π» Code
π Actual behavior
Type alias
Type1
differs from original typeRecord<'field', string>
π Expected behavior
Types of
func1
andfunc2
should be equal and behave the same way, as it worked on 4.1.5 and earlierThe text was updated successfully, but these errors were encountered: