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
Generics with type arguments under mapped type constraint (e.g. Record<string, string>) differ when closing the type argument with type declared with type keyword and interface.
Suppose I have a generic type with mapped type constraint: type A<T extends Record<string, string>> = never;
But when I try to close type A with PersonI I am getting an error 2345, which I didn't get using PersonT. This may potentially lead to bugs (because there is no check for property existence), because T extends Record<string, any> is a popular pattern, which is used when people who don't know the object keyword try to make an object constraint.
Bug Report
Generics with type arguments under mapped type constraint (e.g. Record<string, string>) differ when closing the type argument with type declared with
type
keyword and interface.Suppose I have a generic type with mapped type constraint:
type A<T extends Record<string, string>> = never;
And I have two types with the same shape
But when I try to close type
A
withPersonI
I am getting an error2345
, which I didn't get usingPersonT
. This may potentially lead to bugs (because there is no check for property existence), becauseT extends Record<string, any>
is a popular pattern, which is used when people who don't know theobject
keyword try to make an object constraint.🔎 Search Terms
generic constraint, record constraint
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
TS let me pass type created by
type
keword🙂 Expected behavior
Same behaviors as interface
The text was updated successfully, but these errors were encountered: