question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
jack-williamscommented, Jul 5, 2019

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

3reactions
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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Index signature is missing in type - Stack Overflow
Type 'TestEvents' does not satisfy the constraint 'Record<string, EventHandler>'. Index signature is missing in type 'TestEvents'. typescript.
Read more >
Index signature for type 'X' is missing in type 'Y' in TS
The error "Index signature for type is missing in type" occurs when TypeScript doesn't consider a type that uses an index signature and...
Read more >
Index Signatures - TypeScript Deep Dive - Gitbook
Index Signatures. An Object in JavaScript (and hence TypeScript) can be accessed with a string to hold a reference to any other JavaScript...
Read more >
Understanding and using interfaces in TypeScript
Types of variables are not predictable in JavaScript. ... find this property in the second function call, it throws an error at runtime....
Read more >
private instance variables c# - Durbuy tourisme
This class implements the Serializable interface, and defines a method This ... IO stream object, does not assign it to any TQ: Value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found