TypeScript array with minimum length

Update 2021: shorter notation:

type arrMin1Str = [string, ...string[]]; // The minimum is 1 string.

OR

type arrMin2Strs = [string, string, ...string[]]; // The minimum is 2 strings.

OR

type arrMin3Strs = [string, string, string, ...string[]]; // The minimum is 3 strings.

OR …so on

This is just an addition to @KPD and @Steve Adams answers, since all specified types are the same.
This should be a valid syntax since TypeScript 3.0+ (2018).

Leave a Comment