-
-
Notifications
You must be signed in to change notification settings - Fork 714
MergeDeep : fix producing [never] when merging empty tuples.
#1330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
taiyakihitotsu
wants to merge
9
commits into
sindresorhus:main
Choose a base branch
from
taiyakihitotsu:fix/issue-1200
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+118
−32
Open
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
13cf1d3
fix: #1200 ensure MergeDeep replaces, with recurseIntoArrays option.
taiyakihitotsu bdc473a
doc: comments should start with upper-cases.
taiyakihitotsu f5b0728
test: fix `boolean` which is too widen to test `true` type.
taiyakihitotsu 3ec94d2
fix: `MergeDeep<[], []>` returns `[]` not `never[]`.
taiyakihitotsu 09a503a
test: revert to use `expectType` directly.
taiyakihitotsu 3f981f2
Merge branch 'main' into fix/issue-1200
taiyakihitotsu 0b6d14d
doc: fix arrow tests
taiyakihitotsu 35ceec8
refactor: remove unused import
taiyakihitotsu 6ac63ef
test: add more cases
taiyakihitotsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,10 +15,10 @@ expectType<{}>(mergeDeep({}, {} as const)); | |||||||||||||||||
| expectType<{}>(mergeDeep({} as const, {} as const)); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Test valid signatures for arrays/tuples. | ||||||||||||||||||
| expectType<never[]>(mergeDeep([], [])); | ||||||||||||||||||
| expectType<never[]>(mergeDeep([] as const, [])); | ||||||||||||||||||
| expectType<never[]>(mergeDeep([], [] as const)); | ||||||||||||||||||
| expectType<never[]>(mergeDeep([] as const, [] as const)); | ||||||||||||||||||
| expectType<[]>(mergeDeep([], [])); | ||||||||||||||||||
| expectType<[]>(mergeDeep([] as const, [])); | ||||||||||||||||||
| expectType<readonly []>(mergeDeep([], [] as const)); | ||||||||||||||||||
| expectType<readonly []>(mergeDeep([] as const, [] as const)); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Test invalid signatures. | ||||||||||||||||||
| expectType<never>(mergeDeep({}, [])); | ||||||||||||||||||
|
|
@@ -56,7 +56,7 @@ expectType<Array<string | 42>>(mergeDeep(['life'], [42] as const, {arrayMergeMod | |||||||||||||||||
| expectType<Array<'life' | 42>>(mergeDeep(['life'] as const, [42] as const, {arrayMergeMode: 'replace'})); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Should merge tuples with union | ||||||||||||||||||
| expectType<Array<number | string | boolean>>(mergeDeep(['life', true], [42], {arrayMergeMode: 'spread'})); | ||||||||||||||||||
| expectType<Array<number | string | true>>(mergeDeep(['life', true], [42], {arrayMergeMode: 'spread'})); | ||||||||||||||||||
| expectType<Array<number | string | true>>(mergeDeep(['life'], [42, true], {arrayMergeMode: 'spread'})); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Should not deep merge classes | ||||||||||||||||||
|
|
@@ -325,3 +325,54 @@ type OptionalWithUndefined = {a: string | undefined; b?: number; c?: boolean | u | |||||||||||||||||
|
|
||||||||||||||||||
| expectType<OptionalWithUndefined>({} as MergeDeep<NotOptional, OptionalWithUndefined>); | ||||||||||||||||||
| expectType<NotOptional>({} as MergeDeep<OptionalWithUndefined, NotOptional>); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Test for https://github.com/sindresorhus/type-fest/issues/1200 | ||||||||||||||||||
| type EmptyFoo = {foo: []}; | ||||||||||||||||||
| type NotEmptyTupleFoo = {foo: [0, 1]}; | ||||||||||||||||||
| type NotEmptyArrayFoo = {foo: number[]}; | ||||||||||||||||||
| expectType<NotEmptyTupleFoo>({} as MergeDeep<EmptyFoo, NotEmptyTupleFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyTupleFoo>({} as MergeDeep<NotEmptyTupleFoo, EmptyFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyArrayFoo>({} as MergeDeep<EmptyFoo, NotEmptyArrayFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyArrayFoo>({} as MergeDeep<NotEmptyArrayFoo, EmptyFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Test for https://github.com/sindresorhus/type-fest/issues/1200 | ||||||||||||||||||
| type EmptyReadonlyFoo = {readonly foo: []}; | ||||||||||||||||||
| type NotEmptyReadonlyTupleFoo = {readonly foo: [0, 1]}; | ||||||||||||||||||
| type NotEmptyReadonlyArrayFoo = {readonly foo: number[]}; | ||||||||||||||||||
| expectType<NotEmptyReadonlyTupleFoo>({} as MergeDeep<EmptyReadonlyFoo, NotEmptyReadonlyTupleFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyReadonlyTupleFoo>({} as MergeDeep<NotEmptyReadonlyTupleFoo, EmptyReadonlyFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyReadonlyArrayFoo>({} as MergeDeep<EmptyReadonlyFoo, NotEmptyReadonlyArrayFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyReadonlyArrayFoo>({} as MergeDeep<NotEmptyReadonlyArrayFoo, EmptyReadonlyFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Test for https://github.com/sindresorhus/type-fest/issues/1200 | ||||||||||||||||||
| type EmptyOptionalFoo = {foo?: []}; | ||||||||||||||||||
| type NotEmptyOptionalTupleFoo = {foo?: [0, 1]}; | ||||||||||||||||||
| type NotEmptyOptionalArrayFoo = {foo?: number[]}; | ||||||||||||||||||
| expectType<NotEmptyOptionalTupleFoo>({} as MergeDeep<EmptyOptionalFoo, NotEmptyOptionalTupleFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyOptionalTupleFoo>({} as MergeDeep<NotEmptyOptionalTupleFoo, EmptyOptionalFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyOptionalArrayFoo>({} as MergeDeep<EmptyOptionalFoo, NotEmptyOptionalArrayFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyOptionalArrayFoo>({} as MergeDeep<NotEmptyOptionalArrayFoo, EmptyOptionalFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Test for https://github.com/sindresorhus/type-fest/issues/1200 | ||||||||||||||||||
| type EmptyOptionalReadonlyFoo = {readonly foo?: []}; | ||||||||||||||||||
| type NotEmptyOptionalReadonlyTupleFoo = {readonly foo?: [0, 1]}; | ||||||||||||||||||
| type NotEmptyOptionalReadonlyArrayFoo = {readonly foo?: number[]}; | ||||||||||||||||||
| expectType<NotEmptyOptionalReadonlyTupleFoo>({} as MergeDeep<EmptyOptionalReadonlyFoo, NotEmptyOptionalReadonlyTupleFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyOptionalReadonlyTupleFoo>({} as MergeDeep<NotEmptyOptionalReadonlyTupleFoo, EmptyOptionalReadonlyFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyOptionalReadonlyArrayFoo>({} as MergeDeep<EmptyOptionalReadonlyFoo, NotEmptyOptionalReadonlyArrayFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyOptionalReadonlyArrayFoo>({} as MergeDeep<NotEmptyOptionalReadonlyArrayFoo, EmptyOptionalReadonlyFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Test for https://github.com/sindresorhus/type-fest/issues/1200 | ||||||||||||||||||
| expectType<NotEmptyOptionalReadonlyTupleFoo>({} as MergeDeep<EmptyOptionalFoo, NotEmptyOptionalReadonlyTupleFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyOptionalTupleFoo>({} as MergeDeep<NotEmptyOptionalReadonlyTupleFoo, EmptyOptionalFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<EmptyOptionalFoo>({} as MergeDeep<EmptyOptionalReadonlyFoo, EmptyOptionalFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<EmptyOptionalReadonlyFoo>({} as MergeDeep<EmptyOptionalFoo, EmptyOptionalReadonlyFoo, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
|
|
||||||||||||||||||
| // Test for https://github.com/sindresorhus/type-fest/issues/1200 | ||||||||||||||||||
| type EmptyFooRecursive = {foo: [0, string, {bar: []}]}; | ||||||||||||||||||
| type NotEmptyTupleFooRecursive = {foo: [0, number, {bar: [0, 1]}]}; | ||||||||||||||||||
| type NotEmptyArrayFooRecursive = {foo: [0, number, {bar: number[]}]}; | ||||||||||||||||||
| expectType<NotEmptyTupleFooRecursive>({} as MergeDeep<EmptyFooRecursive, NotEmptyTupleFooRecursive, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<{foo: [0, string, {bar: [0, 1]}]}>({} as MergeDeep<NotEmptyTupleFooRecursive, EmptyFooRecursive, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<NotEmptyArrayFooRecursive>({} as MergeDeep<EmptyFooRecursive, NotEmptyArrayFooRecursive, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
| expectType<{foo: [0, string, {bar: number[]}]}>({} as MergeDeep<NotEmptyArrayFooRecursive, EmptyFooRecursive, {recurseIntoArrays: true; arrayMergeMode: 'replace'}>); | ||||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.