Skip to content

fix(merge-styles): keep same type output for DeepPartialV2 to match original DeepPartial #31856

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: keep same type output for DeepPartialV2 to match original DeepPartial",
"packageName": "@fluentui/merge-styles",
"email": "[email protected]",
"dependentChangeType": "patch"
}
10 changes: 9 additions & 1 deletion packages/merge-styles/src/DeepPartial.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable @fluentui/max-len */

/**
* TypeScript type to return a deep partial object (each property can be undefined, recursively.)
* @deprecated - This type will hit infinite type instantiation recursion. Please use {@link DeepPartialV2}
Expand All @@ -13,8 +15,14 @@ type DeepPartialObject<T> = {
[Key in keyof T]?: DeepPartialV2<T[Key]>;
};

/**
* Why `T extends Function ? {}` :
* While this transform is incorrect, in order not run into infinite type instantiation to maintain type creation compatibility with original {@link DeepPartial} we need to hit `[P in keyof T]? T[P]` part of the mapped type from original,
* which would transform to bottom type `{}` if `Function` would be `T`
*
*/
export type DeepPartialV2<T> = T extends Function
? T
? {}
: T extends Array<infer U>
? IDeepPartialArray<U>
: T extends object
Expand Down
Loading