type omit - nberlette/is GitHub Wiki
export type OmitAny<T, Deep extends boolean = false> = T extends object ? {
[K in [object Object]]: Deep extends true ? OmitAny<T[K], true> : T[K]
} : T;
Omit properties from an object type where the value is any
.
This relies on the IsAny
utility type.
T
-
Deep
extendsboolean
(default:false
)
Types
import type { OmitAny } from "@nick/is/type";
type A = { a: string; b: any; c: number };
type B = OmitAny<A>;
// ^? type B = { a: string; c: number }
export type OmitAnyOrNever<T, Deep extends boolean = false> = T extends object ? {
[K in [object Object]]:
Deep extends true ? OmitAnyOrNever<T[K], Deep> : T[K]
} : T;
Omit properties from an object type where the value is any
or never
.
This relies on the
IsAnyOrNever
utility type.
T
-
Deep
extendsboolean
(default:false
)
Types
import type { OmitAnyOrNever } from "@nick/is/type";
type A = { a: string; b: any; c: number; d: never };
type B = OmitAnyOrNever<A>;
// ^? type B = { a: string; c: number }
export type OmitIndexSignature<T> = {
[K in [object Object]]: T[K]
};
Omit generic index signatures from an object type. This is useful for filtering out index signatures that are too broad, allowing you to clean up a type so it only contains literal properties.
This relies on the
IsIndexSignature
utility type.
T
import type { OmitIndexSignature } from "@nick/is/type";
type A = { 0: "foo"; length: 1; [y: number]: string };
type B = OmitIndexSignature<A>;
// ^? type B = { 0: "foo"; length: 1 }
export type OmitNever<T, Deep extends boolean = false> = T extends object ? {
[K in [object Object]]: Deep extends true ? OmitNever<T[K], Deep> : T[K]
} : T;
Omit properties from an object type where the value is never
.
This relies on the IsNever
utility
type.
T
-
Deep
extendsboolean
(default:false
)
Types
import type { OmitNever } from "@nick/is/type";
type A = Required<{ a: string; b: number } & { b: bigint; c: number }>;
// ^? type A = { a: string; b: never; c: number }
type B = OmitNever<A>;
// ^? type B = { a: string; c: number }
export type OmitNullable<T, Deep extends boolean = false> = T extends object ? {
[K in [object Object]]: Deep extends true ? OmitNullable<T[K], Deep> : T[K]
} : T;
Omit properties from an object type whose value is null
or undefined
.
This relies on the IsNever
utility
type.
T
-
Deep
extendsboolean
(default:false
)
Types
import type { OmitNullable } from "@nick/is/type";
type A = { a: string; b: null; c: number; d: undefined };
type B = OmitNullable<A>;
// ^? type B = { a: string; c: number }
export type OmitUndefined<T, Deep extends boolean = false> = T extends object ? {
[K in [object Object]]: Deep extends true ? OmitUndefined<T[K], Deep> : T[K]
} : T;
Omit properties from an object type whose value is undefined
.
This relies on the IsNever
utility
type.
T
-
Deep
extendsboolean
(default:false
)
Types
import type { OmitUndefined } from "@nick/is/type";
type A = { a: string; b: undefined; c: number };
type B = OmitUndefined<A>;
// ^? type B = { a: string; c: number }
export type OmitUnknown<U, Deep extends boolean = false> = U extends infer T extends object ? {
[K in [object Object]]: Deep extends true ? OmitUnknown<T[K], true> : T[K]
} : IsUnknown<U, never, U>;
Omit properties from an object type where the value is unknown
.
This relies on the IsUnknown
utility type.
U
-
Deep
extendsboolean
(default:false
)
Types
import type { OmitUnknown } from "@nick/is/type";
type A = { a: string; b: unknown; c: number };
type B = OmitUnknown<A>;
// ^? type B = { a: string; c: number }