3 ms·
As the full lesson says: For every soundness-related bug that sneaks through, TypeScript will probably save you from hundreds of "cannot read property of undef
by _0o6v 6y ago
As the full lesson says:
For every soundness-related bug that sneaks through, TypeScript will probably save you from hundreds of "cannot read property of undefined" errors.
- z3t4 6y agoIn JavaScript its good practice to check function parameters for errors. TypeScript (TS) fans call this "poor mans type checker". It has however several benefits over TS. Like more simple then extended type declaration: if(arr.lenght==0) throw new Error("expected arr to be not empty") Vs type NonEmptyArray<T> = [T, ...T[]]; Or if you need to check if the array has exactly 3 items. How would you do that in TS?
- methyl 6y ago> Or if you need to check if the array has exactly 3 items. How would you do that in TS? Like that: https://www.typescriptlang.org/play?#code/C4TwDgpgBAKgFgJwhAksCBbAzlAvFAbS2AQEsA7AcwBopiyrb6LKBdAKHYGMB7c4qBQBuAQwA2pACYAuWImRpMOfAQBEIrJNW1VkiADNVHXv2BRREmXKSp02PIXWbtUXQZerSAKwDWRoA https://www.typescriptlang.org/play?#code/C4TwDgpgBAKgFgJwhA...