diff --git a/change/@fluentui-merge-styles-917f7ae8-0a61-47db-83f7-e29e8264ac4e.json b/change/@fluentui-merge-styles-917f7ae8-0a61-47db-83f7-e29e8264ac4e.json new file mode 100644 index 0000000000000..a8cdf823eb0b4 --- /dev/null +++ b/change/@fluentui-merge-styles-917f7ae8-0a61-47db-83f7-e29e8264ac4e.json @@ -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" +} diff --git a/packages/merge-styles/src/DeepPartial.ts b/packages/merge-styles/src/DeepPartial.ts index ca351bd5feb54..cfca387a79bee 100644 --- a/packages/merge-styles/src/DeepPartial.ts +++ b/packages/merge-styles/src/DeepPartial.ts @@ -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} @@ -13,8 +15,14 @@ type DeepPartialObject = { [Key in keyof T]?: DeepPartialV2; }; +/** + * 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 extends Function - ? T + ? {} : T extends Array ? IDeepPartialArray : T extends object