Thursday, August 6, 2020

typescript-y factoids

I need to up my typescript game so I've been reading the full docs.

I know a lot of people complain about about JS's loosey-goosey ducktype nature, but didn't realize til I read the TS docs that
1 < x < 4
is true no matter what numeric value x is.

Also, I was wondering if typescriptlang.org was the canonical site, with a name like that - guess so. Seems like Typescript is a 2007-2010 era CMS that grabbed the better domain...

Also I'm sort of glad to see that according to the excellent typescript playground, this kind of shenanigans will produce an error:

interface Person {
  name: string;
}

interface Teacher extends Person {
  id: string;
}

interface Student extends Person {
  id: number;
}

interface StudentTeacher extends Teacher, Student {
    catchphrase: string;
}

I remember an old compsci teacher, back when C++ was sort of new, warning us about diamond-shaped inheritance trees. Maybe more problematic when those members were functions vs variables? But still. 

No comments:

Post a Comment