ken
ken

Reputation: 9013

index property forced to string, complains about

I have an interface defined as:

export interface ICardinalityConfig<T> {
  [key: Extract<keyof T, string>]: [number, number] | number | true;
}

but I get an error on on key:

An index signature parameter type must be 'string' or 'number'.

I would have thought that my Extract< ..., string > would have ensured that that condition is met. How do I achieve this goal?

Upvotes: 1

Views: 62

Answers (1)

Lucas
Lucas

Reputation: 10303

It seems like this is not possible yet as of right now (June 2018). No way to represent index signature as a generic type either.

Only string or number keyword can be used for your case.

This issue was opened in 2016 and is still open

Upvotes: 1

Related Questions