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: revert improve type safety in retargeting proxy setter #930

Merged
merged 3 commits into from
Feb 11, 2025

Conversation

alvarosabu
Copy link
Member

This reverts commit 6d8e742.

@alvarosabu alvarosabu added the bug Something isn't working label Feb 10, 2025
Copy link

netlify bot commented Feb 10, 2025

Deploy Preview for tresjs-docs failed. Why did it fail? →

Name Link
🔨 Latest commit 857050b
🔍 Latest deploy log https://app.netlify.com/sites/tresjs-docs/deploys/67ab55c58b71ad0008bfb577

Copy link

pkg-pr-new bot commented Feb 11, 2025

Open in Stackblitz

npm i https://pkg.pr.new/@tresjs/core@930

commit: 857050b

const setter = setters[prop]
if (setter && typeof setter === 'function') {
setter(val, _target, proxy, setTarget)
if (setters[prop]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(non-blocking)

This was showing up as a build error previously ( #924 ). I haven't been able to track down the issue yet, but I think it's due to TS compiler configuration.

  • The TS configuration appears to be updating from time to time, causing old error-free code to throw new errors.
  • The editor TS configuration sometimes appears to be out of sync with the build TS configuration, causing some errors to be invisible in the editor, but thrown during build/CI.

My guess is that for Partial<Record>, we have a different configuration in the editor vs. build, but I haven't been able to track down exactly where.

But the behavior here is consistent with adding/removing the --exactOptionalPropertyTypes compiler option described in this SO question.


The intention for setters is that all values are functions, never explicitly undefined.

setters is currently a Partial<Record>. Depending on configuration, TS will allow Partial<Record> keys to be set to undefined, even if that's not an allowed value in the specific Record type. That would be consistent with the reported build error.

setters doesn't need to be a Partial. So Partial could be removed from its type in this function's arguments. That will keep TS from complaining that undefined values need to be checked, regardless of --exactOptionalPropertyTypes.

Copy link
Contributor

Choose a reason for hiding this comment

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

I pushed a change that removes the Partial from the setters argument type.

It's been part of createRetargetingProxy since I wrote it, but it was ultimately unnecessary.

Removing it will avoid the build error whether TS is configured with or without --exactOptionalPropertyTypes.

Copy link
Member Author

Choose a reason for hiding this comment

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

The only thing I can think of is that the difference between editor and build could be a difference in the versions available in the node modules perhaps? Lets keep an eye on the build typescript issue to see what could be causing the difference between a version or another

Copy link
Member Author

Choose a reason for hiding this comment

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

@andretchen0 should merge this one?

Copy link
Contributor

@andretchen0 andretchen0 Feb 11, 2025

Choose a reason for hiding this comment

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

For me, it's ready to merge.

@alvarosabu alvarosabu merged commit 0a95764 into main Feb 11, 2025
5 of 9 checks passed
@alvarosabu alvarosabu deleted the fix/revert-6d8e742646618bbf40b192bfe5dafa376f8780fe branch February 11, 2025 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants