2 ms·
Indeed, how can you declare a list with some elements nullable, and some not? The result should instead be a tuple, but IDK how well tuple size inference would
by nine_k 7y ago
Indeed, how can you declare a list with some elements nullable, and some not?
The result should instead be a tuple, but IDK how well tuple size inference would work in a case like that.
- 52-6F-62 7y agoI’m not at a computer now, but you can explicitly define a tuple type like: type Tuple<T, K> = [T, K | null]; Which is my first thought, but I can’t test it against the compiler at the moment and I’m not sure if I’m missing something. ...JavaScript would allow you to extend that list during runtime (unless you freeze it) type Tuple<T, K> = [T, K] const Tuple<T, K> = (x: T, y: K): Tuple<T, K> => { const tup = [x, y]; Object.freeze(tup); return tup; };
- amaranth 7y agoHaving it be a tuple would require variadic generics, wouldn't it?