-
Notifications
You must be signed in to change notification settings - Fork 14
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
optionize<ProvidedOptions, SelfOptions>
is buggy
#1360
Comments
optionize<ProvidedOptions, SelfOptions>
is buggy
At first glance I see that this feature isn't inherently broken, as I can trigger an error with this patch in our wilder examples: Index: js/wilder/model/WilderOptionsPatterns.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/wilder/model/WilderOptionsPatterns.ts b/js/wilder/model/WilderOptionsPatterns.ts
--- a/js/wilder/model/WilderOptionsPatterns.ts (revision 4950bcb35d51fbafd86fa63b614955d295b23e2b)
+++ b/js/wilder/model/WilderOptionsPatterns.ts (date 1669410560197)
@@ -159,7 +159,9 @@
private treeType: TreeItemSelfOptions[ 'treeType' ];
public constructor( providedOptions: TreeItemOptions ) {
- const options = optionize<TreeItemOptions, TreeItemSelfOptions, ItemOptions>()( {}, providedOptions );
+ const options = optionize<TreeItemOptions, TreeItemSelfOptions, ItemOptions>()( {
+ treeType: 'pipe'
+ }, providedOptions );
super( options );
this.treeType = options.treeType;
}
It looks like in your case, specifying the parent options Type solves things. That said, looking into optionize and the implementation of @samreid can you please review the commits. @samreid what I am finding here is that this was a regression, and it could have been solved if there was an Thanks all! |
I like the idea of using Subject: [PATCH] Update docs
---
Index: js/common/model/CollisionCounter.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/common/model/CollisionCounter.ts b/js/common/model/CollisionCounter.ts
--- a/js/common/model/CollisionCounter.ts (revision 9dfeb6817d0073efb0862c6420160598ba9cf9a4)
+++ b/js/common/model/CollisionCounter.ts (date 1669730414030)
@@ -18,8 +18,8 @@
import CollisionDetector from './CollisionDetector.js';
type SelfOptions = {
- position?: Vector2;
- visible?: boolean;
+ position: Vector2;
+ visible: boolean;
};
type CollisionCounterOptions = SelfOptions & PickRequired<PhetioObjectOptions, 'tandem'>;
Note that making one of those options required catches the type error, but making both required fails to catch the type error. I'll open an issue in chipper about adding a "this should fail type checking" harness. |
I was finally able to crack it! We are now getting type errors when you add required options in the defaults. This helps to catch duplications that should be handled in other ways. This was not trivial, and there are still multiple TODOs here where I require other people's help. But in general we have fixed one of the primary challenges with optionize. Every spot that I found a type error was buggy, and I was able to fix it up! I just want to say how happy I am about the changes here. There are 15 TODOs marked with this issue
As for the actual commit is phetsims/phet-core@d02125b. I think that I would like to discuss it with @samreid. Questions for us to discuss (sync or async):
Still running git hooks, but I will commit soon. |
Excellent! RE: #1360 (comment) @samreid I updated to use phet-common types, and I'm much happier. From here, all that is left are the TODOs that I need @pixelzoom's help with. |
In the above commits, I addressed all of the TODOs that had my initials "CM" on them. There's one TODO remaining for this issue, in PatternStringProperty.ts:
I spent ~10 minutes on it and got nowhere. You might need to consult with @jonathanolson. |
For the PatternStringProperty case, optionize probably needs to handle more complicated objects. Effectively SelfOptions is |
I added a commit that changes the type parameters to the optionize call in PatternStringProperty. It passes type checking. I don't know of a good long-term fix. @jonathanolson does that seem reasonable to you? |
That seems reasonable, if a bit unfortunate (I understand why). Thanks! |
@zepumph I don't see any more TODOs referencing this issue, can it be closed? |
The 2-parameter form of
optionize
seems to have a serious problem. It's not detecting when defaults are provided for required options. For example, in gas-properties CollisionCounter.ts:In this example, the fields in SelfOptions have accidentally been specified as required, and I've provided default values in the first arg to optionize. With 3-parameters to
optionize
, the default values provided would be flagged as an error. With 2-parameters tooptionize
, this error goes unreported.I've been running into this case quite frequently when converting sims to TypeScript, so I'll start with high-priority.
The text was updated successfully, but these errors were encountered: