3
votes
class One {
  controls: { [key: string]: number };
}

interface Two<T> extends One {
  controls: { [key in keyof T]: number }
}

I get an error that:

TS2430: Interface 'Two' incorrectly extends interface 'One'.   Types of property 'controls' are incompatible.     Type '{ [key in keyof T]: number; }' is not assignable to type '{ [key: string]: number; }'

In typescript playground (click) everything seems to be okay. What is it happening?

Typescript version: 2.4.2

1

1 Answers

0
votes

This was an issue in 2.4, which got fixed in 2.5. You can have a look at the GitHub issue. Basically in 2.4 this is not allowed, in 2.5 it was explicitly allowed:

Mapped types over keyof T [are] subtypes of types with string index signatures