foundry-vtt-types
foundry-vtt-types copied to clipboard
Counter-example for typing `DataField#initial` as `(source: DataModel.Any) => InitializedType`
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.
Did regex for clean.*source
EmbeddedDataFieldpassesvalue, which would be the source data for the embedded model I believe?EmbeddedCollectionDeltaFieldis configured similarly toEmbeddedCollectionFieldbut sometimes deferring to TombstoneData rather than themodelTypeDataFieldsimilarly callscls.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.
Update from discord - looks like it's just AnyObject getting passed through. Only example of actual function-based usage was sight.enabled in Token