From 6ee3f246fa29edf6a5cc28bd5d25b2d7dd06721f Mon Sep 17 00:00:00 2001 From: Edie Lemoine Date: Fri, 1 Mar 2024 12:02:59 +0100 Subject: [PATCH] feat(types): add MakeRequired --- src/__tests__/types/makeRequired.ts | 18 ++++++++++++++++++ src/types/index.ts | 1 + src/types/makeRequired.ts | 1 + 3 files changed, 20 insertions(+) create mode 100644 src/__tests__/types/makeRequired.ts create mode 100644 src/types/makeRequired.ts diff --git a/src/__tests__/types/makeRequired.ts b/src/__tests__/types/makeRequired.ts new file mode 100644 index 0000000..cd6cb9a --- /dev/null +++ b/src/__tests__/types/makeRequired.ts @@ -0,0 +1,18 @@ +import {type MakeRequired} from '../../types'; + +const correct1: MakeRequired<{a?: number; b?: string}, 'a'> = { + a: 1, +}; +const correct2: MakeRequired<{a?: number; b?: string}, 'a' | 'b'> = { + a: 1, + b: 'b', +}; + +// @ts-expect-error +const incorrect1: MakeRequired<{a?: number; b?: string}, 'a'> = { + b: 'b', +}; +// @ts-expect-error +const incorrect2: MakeRequired<{a?: number; b?: string}, 'a' | 'b'> = { + a: 1, +}; diff --git a/src/types/index.ts b/src/types/index.ts index c1e39c5..f17bcde 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -14,3 +14,4 @@ export * from './requireOnly'; export * from './resolvePromise'; export * from './reverseMap'; export * from './valueOf'; +export * from './makeRequired'; diff --git a/src/types/makeRequired.ts b/src/types/makeRequired.ts new file mode 100644 index 0000000..452d9d4 --- /dev/null +++ b/src/types/makeRequired.ts @@ -0,0 +1 @@ +export type MakeRequired = Omit & Required>;