Effect CommunityEC
Effect Community8mo ago
5 replies
jvliwanag

Unexpected behavior of `keyof` with primitive types in TypeScript

Why does keyof on non records behave this way? Does it make sense? I kind of expect for it to error out.

type Moo<T> = { [K in keyof T]: "moo" };
type MooR = Moo<{j: string}>; // Ok: evals to {j: Moo}
type MooS = Moo<string>; // why MooS = string?
type MooN = Moo<number>; // why MooN = number?
Was this page helpful?