4 ms·
In JavaScript its good practice to check function parameters for errors. TypeScript (TS) fans call this "poor mans type checker". It has however several benefit
by z3t4 6y ago
In 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...