5
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 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.