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>;