Skip to content
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": "martinhochel@microsoft.com",
"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