by betenoire · 2y ago · 0 comments
type N = 1 | 2
const x1:N = 1
const x2:N = 1
const sum:N = x1 + x2
Typescript (the version running on my box) considers this an error.Typescript is able to do this with strings when using templates.
type Suit = "C" | "D" | "H" | "S";
type Rank = "A" | "2" | "3" | "4";
type Card = `${Suit}${Rank}`;
const club = "D";
const ace = "A";
const aceOfClubs: Card = `${club}${ace}`;
Even though I have not declared the club or ace as a Suit or Rank, it still infers the Card correctly in the last line. This is a stronger form of typing than what you are settling for where 1..100 doesn't know its own range.This is the difference I'm referring to.
>There is nothing to suggest that 1..100 understands math.
That's like, your opinion man. I'd like it.