Closed chrisklus closed 1 year ago
Patch that @zepumph and I have been experimenting with:
@chrisklus and I had a fruitful exploration into trying to solve this particular issue, but it really ended up bleeding into general problems with optionize as a whole. Some takeaways:
var?: number
as opposed to var: number|undefined
. The first one often doesn't get caught when passing var into something that just takes a number.@ts-expect-error
in WilderOptionsPatterns in attempt to continue to solidify what the optionize functionality is and should be. Lots more work to do!
type DoBetter<SelfOptions, ParentOptions, DefaultOptions, ProvidedOptions> = {
[X in RequiredKeys<SelfOptions & ParentOptions>]: X extends keyof ( DefaultOptions & ProvidedOptions ) ? ( SelfOptions & ParentOptions )[X] : ( SelfOptions & ParentOptions )[X] | undefined
}
Here is the patch that we will almost certainly never look at again. But could!
Latest patch with TODOs for our next steps!
I tried returning the type ParentOptionKeysInDefaults
, and no matter what I put in for extends
, it always gave me the full value, not an inference of just the keys used by the defaults parameter:
ParentOptionKeysInDefaults extends keyof ParentOptions
ParentOptionKeysInDefaults extends DefaultParentUsedKeys<SelfOptions, ParentOptions>
ParentOptionKeysInDefaults extends OptionizeDefaults<SelfOptions, ParentOptions>
I'm not sure how to get the inference working better.
I'm sorry to say this has sat for too long. I can't apply the above patch anymore and this will require some real work to figure out. Let's work on it next time we are in this repo. Thanks!
Let's work on it next time we are in this repo.
Should be next month, FYI.
Updated patch:
Fixed in the commits. I'll add ts-expect-error
for the type errors that were masked by this bug so we can chip away.
Results from chipAway:
We have corrected a deficiency in optionize where it didn't correctly error when you forgot to provide an option that was required by the parent options and not provided in the provided options. Please see https://github.com/phetsims/phet-core/commit/449042e65311361766b8dbc3a06e0f72496c1ff4 for the correction to optionize and see https://github.com/phetsims/circuit-construction-kit-common/commit/8572344194cf584efd36bfe153c0023bc3b7d22b for an example fix. The above 20 errors are ts-expect-error at the moment. You can find the erroneous lines by searching for this issue url https://github.com/phetsims/phet-core/issues/130
. UPDATE: Even better fix below: https://github.com/phetsims/sound/commit/3dc8fb0aa21213dae2a227c3f24e0fccfba12f09
@samreid Any reason why this issue has not been migrated to phet-core, where optionize lives? It is not specific to center-and-variability.
@samreid I'm confused about how you were able to add @ts-expect-error
comments to geometric-optics, natural-selection, ph-scale, and scenery-phet. All of those repos add ESlint rule "@typescript-eslint/ban-ts-comment" in package.json, which should prohibit @ts-expect-error
comments. Thoughts on why this did not fail?
For number play, I think a good solution might be something like this:
For SpectrumSlider, a solution like this seems reasonable to me:
Slider and FaucetNode have similar problems, related to trait AccessibleSlider and options valueProperty
and enabledRangeProperty
. I've created separate issues for those, assigned to @zepumph and @jessegreenberg.
My repos are done, so self unassigning.
@samreid and I took care of Number Play's together, thanks! We think this is all good to close.
@samreid and I were working on omitting ts-expect-error in https://github.com/phetsims/chipper/issues/1366 and found a case where omitting a required super option from the call site option type and then still not including that required option in optionize defaults did not error.
@zepumph was able to take a look with us before having to go and suggested taking a look at example nine in wilder options patterns. We tried using
WithOptional
like in that case but had no luck. @zepumph could you please take a look again sometime, async or pairing with one of us? Thanks!Please look for this issue link in code.