-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: introduce
mergeWithDefaults
and organize how default valu…
…es for config options are set (#18550)
- Loading branch information
1 parent
584a573
commit 0e1f437
Showing
12 changed files
with
571 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import type { Equal, ExpectTrue } from '@type-challenges/utils' | ||
import { mergeWithDefaults } from '../utils' | ||
|
||
const useDefaultTypeForUndefined1 = mergeWithDefaults( | ||
{ | ||
foo: 1, | ||
}, | ||
{}, | ||
) | ||
|
||
const useDefaultTypeForUndefined2 = mergeWithDefaults( | ||
{ | ||
foo: 1, | ||
}, | ||
{ | ||
foo: 2 as number | undefined, | ||
}, | ||
) | ||
|
||
const includeKeyNotIncludedInDefault1 = mergeWithDefaults( | ||
{}, | ||
{ | ||
foo: 2, | ||
}, | ||
) | ||
|
||
const extendTypeWithValueType = mergeWithDefaults( | ||
{ | ||
foo: 1, | ||
}, | ||
{ | ||
foo: 'string' as string | number, | ||
}, | ||
) | ||
|
||
const plainObject = mergeWithDefaults({ foo: { bar: 1 } }, { foo: { baz: 2 } }) | ||
|
||
const nonPlainObject = mergeWithDefaults( | ||
{ foo: ['foo'] }, | ||
{ foo: [0] as number[] | undefined }, | ||
) | ||
|
||
const optionalNested = mergeWithDefaults({ foo: { bar: true } }, { | ||
foo: { bar: false }, | ||
} as { foo?: { bar?: boolean } }) | ||
|
||
export type cases1 = [ | ||
ExpectTrue<Equal<typeof useDefaultTypeForUndefined1, { foo: number }>>, | ||
ExpectTrue<Equal<typeof useDefaultTypeForUndefined2, { foo: number }>>, | ||
ExpectTrue<Equal<typeof includeKeyNotIncludedInDefault1, { foo: number }>>, | ||
ExpectTrue<Equal<typeof extendTypeWithValueType, { foo: string | number }>>, | ||
ExpectTrue<Equal<typeof plainObject, { foo: { bar: number; baz: number } }>>, | ||
ExpectTrue<Equal<typeof nonPlainObject, { foo: string[] | number[] }>>, | ||
ExpectTrue< | ||
Equal<typeof optionalNested, { foo: { bar: boolean } | { bar: boolean } }> | ||
>, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.