News for hackers. Stuff that matters.
Re:TypeScript’s quirks: How inconsistencies make the languag... by jahewson on Saturday February 01, 2020 @12:09AM (#22208828)
Actually this cast is safe in TypeScript, additional variables are unnecessary.

The statement ‘const d: Dog’ and the expression ‘d as Dog’ are equivalent w.r.t. type safety. The compiler will error in both cases the if the value is not a Dog.

Re:TypeScript’s quirks: How inconsistencies make the languag... by agentcooper on Saturday February 01, 2020 @06:56AM (#22210048)
This is not correct. Following example is valid in strict TypeScript:

  interface Dog {
    breed: string;
  }
  const dog = {} as Dog;
  console.log(dog.breed);
Using `as` is very unsafe in TypeScript.

I've collected more quirks of `as` in this playground: https://www.typescriptlang.org/play/index.html#code/PTAEAMEs...