Skip to content

Commit

Permalink
feat(types): add MakeRequired
Browse files Browse the repository at this point in the history
  • Loading branch information
EdieLemoine committed Mar 1, 2024
1 parent 981f383 commit 6ee3f24
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/__tests__/types/makeRequired.ts
Original file line number Diff line number Diff line change
@@ -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,
};
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './requireOnly';
export * from './resolvePromise';
export * from './reverseMap';
export * from './valueOf';
export * from './makeRequired';
1 change: 1 addition & 0 deletions src/types/makeRequired.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type MakeRequired<Type, Keys extends keyof Type> = Omit<Type, Keys> & Required<Pick<Type, Keys>>;

0 comments on commit 6ee3f24

Please sign in to comment.