Skip to content

Commit

Permalink
fix(Object): Optional fields break FromEntries
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWrexes committed Jun 1, 2023
1 parent a68d742 commit 48ebe41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tests/Oject.test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ declare module '../types' {
Expect<
Equal<
FromEntries<
[Entries<Dummy, 'aString'>, Entries<Dummy, 'aNumber'>, Entries<Dummy, 'anObject'>]
[
Entries<Dummy, 'string'>,
Entries<Dummy, 'number'>,
Entries<Dummy, 'object'>,
Entries<Dummy, 'optional'>,
Entries<Dummy, 'polymorphic'>
]
>,
Dummy
>
Expand Down
8 changes: 7 additions & 1 deletion types/Object.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export namespace Object {
= E extends EmptyArray
? {}
: E extends [infer First extends ObjectEntry, ...infer Tail extends ObjectEntry[]]
? MergeInsertions<{[k in First[0]]: First[1]} & FromEntries<Tail>>
? MergeInsertions<
& IfExtends<First[1], NonNullable<First[1]>,
{ [k in First[0]]: First[1] },
{ [k in First[0]]?: First[1] }
>
& FromEntries<Tail>
>
: never
}

0 comments on commit 48ebe41

Please sign in to comment.