Skip to content
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

fix: DeepPartial with generic parameter should allow assigning {} #184

Merged
merged 1 commit into from
Mar 8, 2023
Merged
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
12 changes: 8 additions & 4 deletions src/__snapshots__/mapped-types.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ exports[`DeepNonNullable testType<DeepNonNullable<NestedProps>['first']['second'

exports[`DeepNonNullable testType<DeepNonNullable<NestedProps>['first']['second']['name']>() (type) should match snapshot 1`] = `"string"`;

exports[`DeepPartial testType<DeepPartial<NestedProps>>({}) (type) should match snapshot 1`] = `"DeepPartial<{ first: { second: { name: string; }; }; }>"`;

exports[`DeepPartial testType<DeepPartial<T>>({}) (type) should match snapshot 1`] = `"DeepPartial<T>"`;

exports[`DeepPartial testType<ReturnType<NonNullable<typeof functionProp>>>() (type) should match snapshot 1`] = `"string"`;

exports[`DeepPartial testType<typeof arrayItem.name>() (type) should match snapshot 1`] = `"string | undefined"`;
Expand All @@ -49,13 +53,13 @@ exports[`DeepPartial testType<typeof functionProp>() (type) should match snapsho

exports[`DeepPartial testType<typeof name>() (type) should match snapshot 1`] = `"string | undefined"`;

exports[`DeepPartial testType<typeof nestedArrayPartial.first>() (type) should match snapshot 1`] = `"_DeepPartialObject<{ second: { name: string; }[]; }> | undefined"`;
exports[`DeepPartial testType<typeof nestedArrayPartial.first>() (type) should match snapshot 1`] = `"DeepPartial<{ second: { name: string; }[]; }> | undefined"`;

exports[`DeepPartial testType<typeof nestedFunctionPartial.first>() (type) should match snapshot 1`] = `"_DeepPartialObject<{ second: (value: number) => string; }> | undefined"`;
exports[`DeepPartial testType<typeof nestedFunctionPartial.first>() (type) should match snapshot 1`] = `"DeepPartial<{ second: (value: number) => string; }> | undefined"`;

exports[`DeepPartial testType<typeof partialNested.first>() (type) should match snapshot 1`] = `"_DeepPartialObject<{ second: { name: string; }; }> | undefined"`;
exports[`DeepPartial testType<typeof partialNested.first>() (type) should match snapshot 1`] = `"DeepPartial<{ second: { name: string; }; }> | undefined"`;

exports[`DeepPartial testType<typeof second>() (type) should match snapshot 1`] = `"_DeepPartialObject<{ name: string; }> | undefined"`;
exports[`DeepPartial testType<typeof second>() (type) should match snapshot 1`] = `"DeepPartial<{ name: string; }> | undefined"`;

exports[`DeepReadonly testType<DeepReadonly<DeepReadonly<NestedArrayProps>>>() (type) should match snapshot 1`] = `"_DeepReadonlyObject<{ first: { second: { name: string; }[]; }; }>"`;

Expand Down
18 changes: 13 additions & 5 deletions src/mapped-types.spec.snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
_DeepReadonlyObject,
_DeepRequiredArray,
_DeepRequiredObject,
_DeepPartialObject,
_DeepPartial,
_DeepPartialArray,
RequiredKeys,
OptionalKeys,
Expand Down Expand Up @@ -444,11 +444,11 @@ type RequiredOptionalProps = {
};
};
const partialNested: DeepPartial<NestedProps> = {} as any;
// @dts-jest:pass:snap -> _DeepPartialObject<{ second: { name: string; }; }> | undefined
// @dts-jest:pass:snap -> DeepPartial<{ second: { name: string; }; }> | undefined
testType<typeof partialNested.first>();

const second = partialNested.first!.second;
// @dts-jest:pass:snap -> _DeepPartialObject<{ name: string; }> | undefined
// @dts-jest:pass:snap -> DeepPartial<{ name: string; }> | undefined
testType<typeof second>();

const name = second!.name;
Expand All @@ -462,7 +462,7 @@ type RequiredOptionalProps = {
};

const nestedArrayPartial: DeepPartial<NestedArrayProps> = {};
// @dts-jest:pass:snap -> _DeepPartialObject<{ second: { name: string; }[]; }> | undefined
// @dts-jest:pass:snap -> DeepPartial<{ second: { name: string; }[]; }> | undefined
testType<typeof nestedArrayPartial.first>();

const arrayProp = nestedArrayPartial.first!.second;
Expand All @@ -479,14 +479,22 @@ type RequiredOptionalProps = {
};
};
const nestedFunctionPartial: DeepPartial<NestedFunctionProps> = {};
// @dts-jest:pass:snap -> _DeepPartialObject<{ second: (value: number) => string; }> | undefined
// @dts-jest:pass:snap -> DeepPartial<{ second: (value: number) => string; }> | undefined
testType<typeof nestedFunctionPartial.first>();

const functionProp = nestedFunctionPartial.first!.second;
// @dts-jest:pass:snap -> ((value: number) => string) | undefined
testType<typeof functionProp>();
// @dts-jest:pass:snap -> string
testType<ReturnType<NonNullable<typeof functionProp>>>();

// @dts-jest:pass:snap -> DeepPartial<{ first: { second: { name: string; }; }; }>
testType<DeepPartial<NestedProps>>({});

<T extends object>() => {
// @dts-jest:pass:snap -> DeepPartial<T>
testType<DeepPartial<T>>({});
};
Comment on lines +491 to +497
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it looks exactly as in the ticket, nice :)

}

// @dts-jest:group Brand
Expand Down
10 changes: 9 additions & 1 deletion src/mapped-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
_DeepReadonlyObject,
_DeepRequiredArray,
_DeepRequiredObject,
_DeepPartialObject,
_DeepPartial,
_DeepPartialArray,