Skip to content
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

Interface and type with same shape treated diffrently when comapring to Record<string, unknown> #50700

Closed
kbrilla opened this issue Sep 9, 2022 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@kbrilla
Copy link

kbrilla commented Sep 9, 2022

Bug Report

πŸ”Ž Search Terms

interface, type, Record<string, unknown>

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about interfaces

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

function foo<T extends Record<string, unknown>>(param: T) {}

type type1 = {a: string};

interface interface1 {
    a: string;
    };

function tWrapper(value: type1) {
    foo(value);
}

function iWrapper(value: interface1) {
    foo(value); //error 
   /*
     Argument of type 'interface1' is not assignable to parameter of type 'Record<string, unknown>
     Index signature for type 'string' is missing in type 'interface1'.(2345)
   */ 
}

const i: interface1 = {a: 'interface'};
const t: type1 = {a: 'type'};

tWrapper(t);
tWrapper(i);
iWrapper(t);
iWrapper(i);

πŸ™ Actual behavior

Even though type1 and interface1 have the same shape and variables of their types can be used interchangeably as see that there are no errors in

tWrapper(t);
tWrapper(i);
iWrapper(t);
iWrapper(i);

πŸ™‚ Expected behavior

interface and type with same shape works the same

@MartinJohns
Copy link
Contributor

MartinJohns commented Sep 9, 2022

This is working as intended. interface and type are not interchangeably.

Duplicate of #42825. See also #15300 (comment).

@jakebailey jakebailey added the Duplicate An existing issue was already created label Sep 10, 2022
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants