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

Counter-example for typing DataField#initial as (source: DataModel.Any) => InitializedType #2748

Open
LukeAbby opened this issue Aug 5, 2024 · 2 comments

Comments

@LukeAbby
Copy link
Collaborator

LukeAbby commented Aug 5, 2024

So far I've only identified one place that a DataField#initial is called with an argument and that is in EmbeddedCollectionField#_cleanType:

return value.map(v => this.schema.clean(v, {...options, source: v}));

this.schema is a SchemaField so this calls SchemaField#clean (no specific override here) so it goes to DataField#clean which has this line:

if ( value === undefined ) return this.getInitialValue(options.source);

and getInitialValue is:

  getInitialValue(data) {
    return this.initial instanceof Function ? this.initial(data) : this.initial;
  }

Therefore DataField#initial is called with source: v which will be some Document. I've typed DataField#initial based off of this but there may be counterexamples out there.

@LukeAbby LukeAbby changed the title Countexample to DataField#initial: (source: DataModel.Any) => InitializedType Counter-example for typing DataField#initial as (source: DataModel.Any) => InitializedType Aug 5, 2024
@JPMeehan
Copy link
Collaborator

JPMeehan commented Aug 5, 2024

Did regex for clean.*source

  • EmbeddedDataField passes value, which would be the source data for the embedded model I believe?
  • EmbeddedCollectionDeltaField is configured similarly to EmbeddedCollectionField but sometimes deferring to TombstoneData rather than the model
  • TypeDataField similarly calls cls.cleanData(value, {...options, source: value});

I think though in each of these cases we're dealing with the json-serializable _source data rather than the model instance itself.

@JPMeehan
Copy link
Collaborator

JPMeehan commented Aug 6, 2024

Update from discord - looks like it's just AnyObject getting passed through. Only example of actual function-based usage was sight.enabled in Token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants