phetsims / tandem

Simulation-side code for PhET-iO
MIT License
0 stars 5 forks source link

Improve the serialization types for IO Type #274

Closed samreid closed 1 year ago

samreid commented 1 year ago

Related to https://github.com/phetsims/tandem/issues/263 and https://github.com/phetsims/tandem/issues/273, we should improve the serialization features for IO Type.

samreid commented 1 year ago
samreid commented 1 year ago

If I try splitting up the deserialization options, to say it either has fromStateObject or something else (but not both), at the moment I mark fromStateObject?:never in the bottom part, it thinks the entire options object is never:

// If it is serializable, then it is optionally deserializable via one of these methods
type DeserializationOptions<T, StateType> = {
  fromStateObject: ( s: StateType ) => T;
  stateToArgsForConstructor?: never;
  applyState?: never;
  defaultDeserializationMethod?: DeserializationType;
  addChildElement?: never;
} | {
  fromStateObject?: never; // <--- HERE
  stateToArgsForConstructor?: ( s: StateType ) => unknown[];
  applyState?: ( t: T, state: StateType ) => void;
  defaultDeserializationMethod?: DeserializationType;
  addChildElement?: AddChildElement;
};
samreid commented 1 year ago

I feel the long-term antidote for this problem is https://github.com/phetsims/tandem/issues/275. Not sure if any of its ideas can be backpropagated to improve our short-term solution. My recommendation is to close this issue and wait until we can work on https://github.com/phetsims/tandem/issues/275. I'll check in with @zepumph first.

zepumph commented 1 year ago

Yes, this seems like a duplicate at this point. Closing