PartialDeep: Fix behaviour with functions containing multiple call signatures#1259
Conversation
| expectType<{p1: string}>({} as Simplify<typeof functionWithProperties4>); | ||
| expectType<string>(functionWithProperties4(1)); | ||
| expectType<number>(functionWithProperties4('foo', 1)); | ||
| expectNotType<{p1: string}>({} as Simplify<typeof functionWithProperties4>); |
There was a problem hiding this comment.
Removed @ts-expect-error because that's not reliable, not all "tsd" errors surface as TypeScript errors.
| ? Promise<RequiredDeep<ValueType>> | ||
| : T extends (...arguments_: any[]) => unknown | ||
| ? {} extends RequiredObjectDeep<T> | ||
| ? IsNever<keyof T> extends true |
There was a problem hiding this comment.
This is better than {} extends RequiredObjectDeep<T> because {} extends things like {a?: string}, so in PartialDeep we couldn't have used this approach.
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the PartialDeep utility type where functions with multiple call signatures were not properly handled, causing the call signatures to be lost while making properties optional. The fix aligns the behavior with RequiredDeep by bypassing such inputs to preserve function call signatures.
- Updated
PartialDeepto handle functions with multiple call signatures correctly - Added comprehensive test coverage for the new behavior
- Aligned the implementation approach with existing
RequiredDeepbehavior
Reviewed Changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test-d/partial-deep.ts | Adds tests for functions with multiple call signatures to verify call signatures are preserved |
| test-d/required-deep.ts | Updates existing tests to verify call signatures are preserved and uses expectNotType for properties |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
4aae28e to
1c7cb65
Compare
This PR adds handling of multiple call signatures in
PartialDeep, similar toRequiredDeep.Currently, if
PartialDeepis instantiated with a function containing multiple call signatures and a property, the call signatures are not preserved in the resultant type. This PR fixes this by simply bypassing such inputs, similar to how it's done inRequiredDeep.Current behaviour:
Fixed behaviour: