I wouldn’t assemble the Descriptor / ActionDescriptor type from other types - that would be incorrect and also hardly maintainable, as Descriptors will be added with every new feature.
Their types are actually quite uncomplicated.
A Descriptor is literally an object (so it can have any key+value pair) and an ActionDescriptor must have an _obj
key and any additional key/value pair.
You could of course write ActionDescriptor types for specific events, something like "setLayerEffectsDescriptor"
:
export interface PropertyReference<Property extends string = ''> {
_ref: 'property'
_property: Property
}
export interface LayerReference {
_ref: 'layer'
}
export interface SetLayerEffectsDescriptor {
_obj: 'set',
_target: [
PropertyReference<'layerEffects'>,
LayerReference,
],
to: Partial<LayerEffectsDescriptor>,
}
which can then be used to type-savely create the following function:
export function __setLayerEffects(layerEffects: Partial<LayerEffectsDescriptor>, id?: number): SetLayerEffectsDescriptor {
return {
_obj: 'set',
_target: [
{
_ref: 'property',
_property: 'layerEffects',
},
id ? layerRefID(id) : layerRef,
],
to: layerEffects,
}
}
I don’t really see that much use in it though… I was able to write the function also without the specific typing - the return type could just be ActionDescriptor
or any
after all. You’re just gonna throw it into a batchPlay call, so the type of it doesn’t really matter, does it? For getters in comparison, you keep working on their return value after calling them, so it’s helpful to have the types.
In theory you could abstract the above types even more until you have something like
export interface setPropertyDescriptor<PropertyType, PropertyName extends string = ''> {
_obj: 'set',
_target: [
PropertyReference<PropertyName>,
Reference,
],
to: Partial<PropertyType>,
}
However, what would you do with it then. Well, you could easily write a function to set any property of any class object in Photoshop (Layer, App, Document, …), but it would be quite an abstract function. I’d prefer more specific functions, such a the setLayerEffects()
from above.
Nope, didn’t add anything from there.
I just finished (99% of) the Application Descriptor which was quite exhausting
I’ll push this, the Document Descriptor and some Reference Types to my repo tomorrow.