Get union type from indexed object values

You can use a type query with the result of keyof:

type V = X[keyof X]

Generally a type query will return a union of all possible field types, so X['a'] | X['b'] is the same as X['a' | 'b']. This is why X[keyof X] works, as keyof will return a union of string literal types representing all keys in the object.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)