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...
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.