-
-
Notifications
You must be signed in to change notification settings - Fork 667
Merge: Ensure idempotency so Merge<A, A> returns A
#1336
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
base: main
Are you sure you want to change the base?
Merge: Ensure idempotency so Merge<A, A> returns A
#1336
Conversation
|
@taiyakihitotsu I don't get this, if the problem is with If I understand correctly, this is the problem, right? // Idempotency
type Test1 = {a: string} & {b: string};
expectType<Test1>({} as Merge<Test1, Test1>);The above test still fails. Wrapping |
|
Probably |
Co-authored-by: Som Shekhar Mukherjee <49264891+som-sm@users.noreply.github.com>
c5a99cf to
02b412b
Compare
|
Thanks! I re-read the official doc of intersection, I finally fix my misunderstanding. As the above doc and you mentioned, I've added new 2 commits.
So finally this PR fixes:
|
|
I've added this change, b101b8e, but the following errors occur:
|
The non-simplified version, i.e.,
That’s right, type TestIntersectionObject = {a: string} & {b: string};
expectType<TestIntersectionObject>({} as Merge<TestIntersectionObject, TestIntersectionObject>);Also, it looks like we're mixing two different problems over here.
So, please open a separate PR for the Also, inside type TestIntersectionObject = {a: string} & {b: string};
expectType<TestIntersectionObject | {a: string; b: string; c: string}>({} as Merge<TestIntersectionObject | {c: string}, TestIntersectionObject>);
expectType<TestIntersectionObject | {a: string; b: string; c: string}>({} as Merge<TestIntersectionObject, TestIntersectionObject | {c: string}>);
Please remove this, it's not required. |
Use this PR for the |
Co-authored-by: Som Shekhar Mukherjee <49264891+som-sm@users.noreply.github.com>
Thanks, I've removed
I got it!
I separated the
Addressed. I separated
|
FixedLengthArray in MergeMerge
|
Thanks for your quick review! |
MergeMerge: Ensure idempotency so Merge<A, A> returns A
Current Status
See: #1336 (comment) -> #1336 (comment)
Below the first my comment is wrong because my misunderstanding about branded type and intersection of objects.
Mainly changesFixedLengthArrayBackground
Object merged viaSimplifyand&(e.g.,{a: 0, b: 0}) and those merged only via&(e.g.,{a: 0} & {b: 0}) shouldn't be treated as the same type, to consider Branded Type or the fact that intersection types are handled as distinct constructs.In the previous (meaning before this PR, fa55f48)FixedLengthArraydefinition, the internal objects are directly merged only via&which broke the idempotency ofMerge.So the previous status:General Rule:Merge<A, A>should be identical toAitself, despite a lack of test cases.But,Merge<A, A>did not result in exactlyAwhenFixedLengthArraywas involved.Major Changes
New Test Cases: Added tests intest-d/is-equal.tsandtest-d/merge.tsto ensureMergeidempotency and strict handling of Branded Types.FixedLengthArrayFix: Updated the definition to useSimplifyfor internal object merging.NowMerge<FixedLengthArray<A, L>, FixedLengthArray<A, L>>is equivalent toFixedLengthArray<A, L>.Minor Changes
Refactoring
source/is-equal.d.ts