🏷️(react) add WithOptional type

This type allows to make only specific attributes optionnal where
the existing Partial<T> makes all the attributes optionnal. Its
first use will be for Modals.
This commit is contained in:
Nathan Vasse
2024-01-18 14:38:12 +01:00
committed by NathanVss
parent 7dcf08d308
commit 3d4236c7bd

View File

@@ -5,3 +5,7 @@ export type PartialNested<T> = {
export type PartialExtendableNested<T> = {
[K in keyof T]?: T[K] extends object ? PartialExtendableNested<T[K]> : T[K];
} & Record<PropertyKey, any>;
// From https://github.com/Microsoft/TypeScript/issues/25760#issuecomment-405931434.
export type WithOptional<T, K extends keyof T> = Omit<T, K> &
Partial<Pick<T, K>>;