Skip to content

False positive error report for interface type missing index signature, thus not assignable to object type with unknown values. #32263

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

Open
woutervh- opened this issue Jul 5, 2019 · 6 comments
Assignees
Labels
Docs The issue relates to how you learn TypeScript

Comments

@woutervh-
Copy link

woutervh- commented Jul 5, 2019

TypeScript Version: 3.6.0-dev.20190704 (3.4.3 doesn't have this bug)

Search Terms:
index signature, unknown, assignable, interface

Code

interface A {
  properties?: { [Key: string]: unknown };
}

type Bar = {
  key?: "value";
};

interface Baz {
  key?: "value";
}

interface B extends A { // ok
  properties?: Bar;
}

interface C extends A { // error: Baz is not assignable to { [Key: string]: unknown } -> Index signature is missing
  properties?: Baz;
}

Expected behavior:
No error expected, interface C extends A correctly.

Actual behavior:
Error because interface C does not extend interface A

Playground Link:
http://www.typescriptlang.org/play/#code/JYOwLgpgTgZghgYwgAgILIN4ChnIA5QD2e0YwEAzgPwBcmyA2gNIQCedFYUoA5gLp0AriADWIQgHcQyAL4BuLDKxYwrEsgBCcKMgC8mHMhFtayAEQA3OABtBEMwvnLQkWIhRaAXgdzHWpyxs7B0VncGh4JE1kCAAPSBAAEwo0egB6NORCEUMCYlJyajotKEcw10iUAGEY+IgklPQMZAyYqCIoYrhvYBTxMGQ4CgpgHhA4ACNrFDBCemY2Di5eAWRhMUlpGWQAWgA+ZABJJLjkEbG4MEEoFF7kAFtekZAeXKISKDJKUy8yoA

Related Issues:
#30977 (this one is specifically for enums)

@jack-williams
Copy link
Collaborator

I believe this is working as intended: object literal types have implicit index signatures, while interfaces do not. See the implementation here: #7029

@woutervh-
Copy link
Author

woutervh- commented Jul 5, 2019

Thanks @jack-williams , I didn't know about this specific assignability rule. Do you know if there is a comprehensive list of type assignability rules out there? I tried to search for one but couldn't find.

@jack-williams
Copy link
Collaborator

Not really - If you want to know the absolute truth you need to go here:

The spec is pretty good, although incomplete:

And something to keep an eye on:

@fatcerberus
Copy link

I hate that checker.ts is so absolutely ginormous that GitHub refuses to display it - it makes it impossible to link to specific lines.

@jack-williams
Copy link
Collaborator

The reason intellisense for TypeScript is so performant is because the TypeScript team want to have auto-completion while editing checker.ts[1] - so if anything, we should be encouraging them to make it larger.

[1] I made that up

@RyanCavanaugh RyanCavanaugh added the Docs The issue relates to how you learn TypeScript label Jul 8, 2019
@RyanCavanaugh RyanCavanaugh self-assigned this Jul 8, 2019
@RyanCavanaugh
Copy link
Member

I need to add this to the interfaces vs type aliases section.

... if anything, we should be encouraging them to make it larger.

I feel seen. Also we should make the binder incremental.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs The issue relates to how you learn TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants