notIncludes
The notIncludes() function checks that an array does not contain a given value and acts as a type guard to exclude this value from the typing.
Interactive example
Syntax
Classic signature
typescript
function notIncludes<
GenericArrayValue extends unknown,
const GenericNotIncludeValue extends RemoveFromUnion<
Extract<GenericArrayValue, NotIncludeValue>,
Exclude<NotIncludeValue, null | undefined>
>,
>(
input: readonly GenericArrayValue[],
value: GenericNotIncludeValue,
): input is Exclude<
GenericArrayValue,
GenericNotIncludeValue
>[]Curried signature
typescript
function notIncludes<
GenericArrayValue extends unknown,
const GenericNotIncludeValue extends RemoveFromUnion<
Extract<GenericArrayValue, NotIncludeValue>,
Exclude<NotIncludeValue, null | undefined>
>,
>(
value: GenericNotIncludeValue,
): (input: readonly GenericArrayValue[]) => input is Exclude<
GenericArrayValue,
GenericNotIncludeValue
>[]Parameters
input: Source array.value: Value whose absence you want to guarantee in the array.
Return value
A boolean. When true, TypeScript knows that the array does not contain value and removes the value from the element type.
