Skip to content

Difference of Type and Interface in constraint behavior. #45403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
val-o opened this issue Aug 10, 2021 · 2 comments
Closed

Difference of Type and Interface in constraint behavior. #45403

val-o opened this issue Aug 10, 2021 · 2 comments

Comments

@val-o
Copy link

val-o commented Aug 10, 2021

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

type PersonT = {
    name: string;
}

interface PersonI {
    name: string;
}

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.

🔎 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

@MartinJohns
Copy link
Contributor

Duplicate of #42825. Used search terms: interface extends record unknown

@val-o
Copy link
Author

val-o commented Aug 10, 2021

@MartinJohns thanks! closing

@val-o val-o closed this as completed Aug 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants