TypeScript conditional types constrain no longer working after v3.5.1

Viewed 38

This works as expected <=v3.3.3 (Playground Link)

type StringConstrain<T> = { [K in keyof T]: T[K] extends string ? T[K] : never }
type WantString<T extends string> = number
type Test<T extends StringConstrain<T>> = { [K in keyof T]: WantString<T[K]> }

In 3.5.1 and above, including latest 3.9.2, it reports (Playground Link)

Type 'T[K]' does not satisfy the constraint 'string'.
  Type 'T[keyof T]' is not assignable to type 'string'.
    Type 'T[string] | T[number] | T[symbol]' is not assignable to type 'string'.
      Type 'T[string]' is not assignable to type 'string'.(2344)

I don't understand the new behavior and if this is not a bug, what's the intended way of achieving the same type constrain after 3.5.1?

0 Answers
Related