top | item 35192671 (no title) NoInkling | 3 years ago > there is currently no sensible way to type a non empty array in TypescriptIf we remove the "sensible" requirement: type NonEmptyArray = [any, ...any[]] discuss order hn newest triyambakam|3 years ago Or better: type NonEmptyArray = [unknown, ...unknown[]]; const nea: NonEmptyArray = []; // ^^^ Type '[]' is not assignable to type 'NonEmptyArray'. // Source has 0 element(s) but target requires 1. throwaway09432|3 years ago Can you map over this and preserve the NonEmptyArray type? load replies (1)
triyambakam|3 years ago Or better: type NonEmptyArray = [unknown, ...unknown[]]; const nea: NonEmptyArray = []; // ^^^ Type '[]' is not assignable to type 'NonEmptyArray'. // Source has 0 element(s) but target requires 1. throwaway09432|3 years ago Can you map over this and preserve the NonEmptyArray type? load replies (1)
throwaway09432|3 years ago Can you map over this and preserve the NonEmptyArray type? load replies (1)
triyambakam|3 years ago
throwaway09432|3 years ago