2 replies
April 2024

bouzlibop

Let’s put as Key aside for now […]

What does as Key do? Either I just can’t find it or it was never explained later in the article.

1 reply
June 2024 ▶ bouzlibop

dannymcgee

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.