NotNever<T, N>: N extends [infer Head, ...(infer Tail)]
    ? Head extends string & keyof T
        ? [T[Head]] extends [never]
            ? {
                __error__: `${Head} is never`;
            }
            : Tail extends string[]
                ? NotNever<T, Tail extends (string & keyof T)[]
                    ? Tail
                    : []>
                : true
        : true
    : true

Returns true if no property of T indicated in N has a never type.

Type Parameters

  • T extends object

    The object type to check for never properties.

  • N extends (string & keyof T)[]

    A tuple of keys of T to check for never type.

true if no property of T indicated in N has a never type, otherwise a custom error type.

type ReturnsTrue = NotNever<{ a: string; b: number; c: boolean }, ['b', 'c']>;
// true

type ReturnsError = NotNever<{ a: string; b: number; c: never }, ['b', 'c']>;
// { __error__: 'c is never' }