3 ms·
For those unfamiliar with TS, the above is just... function flat([head, ...tail]) { return Array.isArray(head) ? [...flat(head), ...flat(tail
by kaoD 11mo ago
For those unfamiliar with TS, the above is just...
function flat([head, ...tail]) {
return Array.isArray(head)
? [...flat(head), ...flat(tail)]
: [head, ...flat(tail)]
}
...in TS syntax.
- tomsmeding 11mo agoWell, it is the type of that, in TS syntax. Few are the statically-typed languages that can even express that type.
- not_kurt_godel 11mo agoJava: List<Object> Python: list[Any] ...what am I missing?
- sli 11mo agoYou're missing the input type, essentially. Those are just array types. The TypeScript type signature more of a function type, it expresses flattening a n-dimensional array (input type) into a flat array (output type).
- rjh29 11mo agoYou're missing the specialisation of Object/Any. For example Array.flat called with [int, [bool, string]] returns a type [int, bool, string]. Admittedly this is somewhat niche, but most other languages can't express this - the type information gets erased.