4 ms·
While the article does advocate for objects vs arrays for returning multiple values I wanted to address the second part of you comment. It will work just fine
by aurbano 6y ago
While the article does advocate for objects vs arrays for returning multiple values I wanted to address the second part of you comment.
It will work just fine in TypeScript, where you can define a "fixed size" array as a type:
type Test = [number, string];
const test: Test = [1, 'something'];
The second line will fail compilation if there's a different number of elements in that array, or if the types don't match.
- forest_dweller 6y agoI had misread it. As for the custom type in typescript. I am not too keen on that approach but I suppose it is valid.