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

Conversation

mpiniarski
Copy link
Contributor

Description

DeepPartial supports the assignment of {} when the passed type is generic:

const result: DeepPartial<T> = {}

It's not possible to test with dts-jest, so I setup an additional tsconfig.test-d.json used to run tsc on src/**/*.test-d.ts files.
It would be even better to integrate types testing library like tsd, to be able to assert also cases when type error is expected.

Related issues:

Checklist

  • I have read CONTRIBUTING.md
  • I have linked all related issues above
  • I have rebased my branch

For bugfixes:

  • I have added at least one unit test to confirm the bug have been fixed
  • I have checked and updated TOC and API Docs when necessary

@mpiniarski
Copy link
Contributor Author

@piotrwitek can you take a look?
What do you think about tests?

@piotrwitek
Copy link
Owner

@mpiniarski thanks I'll tomorrow morning :)

@@ -1,8 +1,7811 @@
{
Copy link
Owner

Choose a reason for hiding this comment

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

@mpiniarski could you please remove the package-lock file from the PR, it shouldn't be committed as it's unrelated

Comment on lines 494 to 497
<T extends object>() => {
// @dts-jest:pass:snap -> DeepPartial<{ first: { second: { name: string; }; }; }>
testType<DeepPartial<NestedProps>>({});
};
Copy link
Owner

@piotrwitek piotrwitek Mar 1, 2023

Choose a reason for hiding this comment

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

@mpiniarski I think this test should look like this to reflect the original issue report, could you try it?

<T extends{}>() => {
    // @dts-jest:pass:snap -> I'm not sure about what type will be resulting here from dts as it's using generic
    // possibly ` DeepPartial<T>`, let me know we'll figure it out
    testType<DeepPartial<T>>({});
  };

In summary, whatever dts will derive and there is no error from the compiler on test assignments we can assume it's working correctly

@piotrwitek
Copy link
Owner

Hey @mpiniarski, have you seen my comments?

@mpiniarski mpiniarski force-pushed the fix/DeepPartial-with-generics branch from 68e9db6 to 170ce52 Compare March 8, 2023 13:28
@mpiniarski
Copy link
Contributor Author

Fixed, sorry for the delay.

@piotrwitek
Copy link
Owner

No problem, thanks a lot. I'll have a look shortly :)

Comment on lines +491 to +497
// @dts-jest:pass:snap -> DeepPartial<{ first: { second: { name: string; }; }; }>
testType<DeepPartial<NestedProps>>({});

<T extends object>() => {
// @dts-jest:pass:snap -> DeepPartial<T>
testType<DeepPartial<T>>({});
};
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 :)

Copy link
Owner

@piotrwitek piotrwitek left a comment

Choose a reason for hiding this comment

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

Amazing work @mpiniarski thanks again :)

@piotrwitek piotrwitek merged commit 7c194c0 into piotrwitek:master Mar 8, 2023
@piotrwitek piotrwitek added this to the 3.11.0 milestone Mar 8, 2023
macchiitaka pushed a commit to macchiitaka/tasks-app-nextjs that referenced this pull request Jan 22, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [utility-types](https://togithub.com/piotrwitek/utility-types) |
[`3.10.0` ->
`3.11.0`](https://renovatebot.com/diffs/npm/utility-types/3.10.0/3.11.0)
|
[![age](https://developer.mend.io/api/mc/badges/age/npm/utility-types/3.11.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/utility-types/3.11.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/utility-types/3.10.0/3.11.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/utility-types/3.10.0/3.11.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>piotrwitek/utility-types (utility-types)</summary>

###
[`v3.11.0`](https://togithub.com/piotrwitek/utility-types/releases/tag/v3.11.0)

[Compare
Source](https://togithub.com/piotrwitek/utility-types/compare/v3.10.0...v3.11.0)

#### What's Changed

- Fix a typo in README by [@&#8203;gamtiq](https://togithub.com/gamtiq)
in
[piotrwitek/utility-types#153
- add "Nullish" type alias by
[@&#8203;zhirzh](https://togithub.com/zhirzh) in
[piotrwitek/utility-types#152
- Fix typo in $Call documentation by
[@&#8203;kumar303](https://togithub.com/kumar303) in
[piotrwitek/utility-types#154
- Link to ReturnType from $Call docs by
[@&#8203;kumar303](https://togithub.com/kumar303) in
[piotrwitek/utility-types#155
- fix: ReadOnly<T> has a typo in its documentation
([#&#8203;156](https://togithub.com/piotrwitek/utility-types/issues/156))
by [@&#8203;cyli2014](https://togithub.com/cyli2014) in
[piotrwitek/utility-types#157
- fix: DeepPartial with generic parameter should allow assigning {} by
[@&#8203;mpiniarski](https://togithub.com/mpiniarski) in
[piotrwitek/utility-types#184
- Fix typo in $Call comment by
[@&#8203;Yuddomack](https://togithub.com/Yuddomack) in
[piotrwitek/utility-types#185

#### New Contributors

- [@&#8203;gamtiq](https://togithub.com/gamtiq) made their first
contribution in
[piotrwitek/utility-types#153
- [@&#8203;zhirzh](https://togithub.com/zhirzh) made their first
contribution in
[piotrwitek/utility-types#152
- [@&#8203;kumar303](https://togithub.com/kumar303) made their first
contribution in
[piotrwitek/utility-types#154
- [@&#8203;cyli2014](https://togithub.com/cyli2014) made their first
contribution in
[piotrwitek/utility-types#157
- [@&#8203;mpiniarski](https://togithub.com/mpiniarski) made their first
contribution in
[piotrwitek/utility-types#184
- [@&#8203;Yuddomack](https://togithub.com/Yuddomack) made their first
contribution in
[piotrwitek/utility-types#185

**Full Changelog**:
piotrwitek/utility-types@v3.10.0...v3.11.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 10pm every weekday,before 5am
every weekday,every weekend" in timezone Asia/Tokyo, Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/macchiitaka/tasks-app-nextjs).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4xMzUuMCIsInVwZGF0ZWRJblZlciI6IjM3LjEzNS4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DeepPartial does not allow empty object for generics
2 participants