I could be wrong, but I suspect it’s just a kludge to disambiguate the following extends
clause? In the phrase Key in keyof T extends...
, extends
could either refer to Key
or T
. So maybe inserting as Key
before extends
forces the Key extends...
interpretation instead of T extends...
. Otherwise it’s just a pointless cast, like writing let foo: string = "foo" as string;
TypeScript has probably the most expressively powerful type system on the planet, and I love it for that, but the syntax around generic constraints is super awkward. I wish it just had where
clauses like C# or Rust.