|
|
|
|
|
by z3t4
1992 days 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? |
|
Like that: https://www.typescriptlang.org/play?#code/C4TwDgpgBAKgFgJwhA...