Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed Nov 15, 2022
1 parent 5c5b903 commit 918c00f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions js/wilder/model/WilderOptionsPatterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

import optionize, { combineOptions, EmptySelfOptions, optionize3, OptionizeDefaults } from '../../../../phet-core/js/optionize.js';
import merge from '../../../../phet-core/js/merge.js';
import WithOptional from '../../../../phet-core/js/types/WithOptional.js';
import wilder from '../../wilder.js';
import StrictOmit from '../../../../phet-core/js/types/StrictOmit.js';

Expand Down Expand Up @@ -384,7 +385,7 @@ console.log( new WrapType( {
} ) );

////////
// Example Nine: A work around to Limitation (I)
// Example Nine: Supertype has a required option and subtype makes that option optional with a default.
type HowSuper = 'totally' | 'a bit' | 'no, not really';

type SuperOptions = {
Expand All @@ -406,25 +407,28 @@ class Super {
type KingSelfOptions = {
hasGoodGroceries?: boolean;
};
type KingOptions = KingSelfOptions & Partial<SuperOptions>;
type KingOptions = KingSelfOptions & WithOptional<SuperOptions, 'howSuper'>;

class King extends Super {
public constructor( providedOptions?: KingOptions ) {

// Without the 4th type arg, the super() call doesn't know that howSuper has been provided. This is a workaround
// for Limitation (I). Ideally, we wouldn't need the 4th parameter here.
const options = optionize<KingOptions, KingSelfOptions, SuperOptions>()( {
howSuper: 'totally',
hasGoodGroceries: true
} );
}, providedOptions );
super( options );
}
}

const kingSuper = new King( {
const kingSuper1 = new King( {
hasGoodGroceries: true,
howSuper: 'a bit'
} );

const kingSuper2 = new King( {
hasGoodGroceries: false
} );
console.log( kingSuper );
console.log( kingSuper1 );
console.log( kingSuper2 );


////////
Expand Down

0 comments on commit 918c00f

Please sign in to comment.