microsoft / microsoft/TypeScript

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

Open
#32,263 6 comments 0 reactions 1 assignee View on GitHub

@RyanCavanaugh is already working on this.

Since Jul 8, 2019.

Docs
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.