Skip to content

Latest commit

 

History

History
68 lines (48 loc) · 1019 Bytes

File metadata and controls

68 lines (48 loc) · 1019 Bytes

typelab / utils / ArrayPartial

type ArrayPartial<T, Index> = T extends ReadonlyArray<infer Element> ? _IfNotAnyOrNever<T, _IfNotAnyOrNever<Index, _ArrayPartial<T, Index, Element>>> : never;

Extended TypeScript `Partial` to handle Array.

Type Parameters

Type Parameter Default type Description

T

The original Array type.

Index

ArrayIndexes<T, true>

The index of T that should be required.

Returns

An Array type with the specified Index set as required.

Example

type Result1 = ArrayPartial<[string, string]>; // [string?, string?]
type Result2 = ArrayPartial<[string, string], 1>; // [string, string?]
type Never1 = ArrayPartial<[string, string], any>; // never
type Never2 = ArrayPartial<any, 1>; // never