You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I want to modify asset folders, I have to specify patch operations. The SDK provides the AssetFolderModels.IModifyAssetFoldersData type for the operations. The problem is that this type doesn't guide me as to what properties are needed for different patch operations. I always have to check with the docs for what kind of properties I have to provide. It is unnecessarily difficult and opens up opportunities for mistakes. For example, when removing a folder I only have to specify the reference property, but when renaming, I also have to specify the value property.
Properties also can have different types based on the operation type. For example, when renaming a folder, the value property has to be of type string (the new name), but when adding a folder, the same property value has to be an object specifying the folder object.
Example:
// ....withData([{op: "addInto",value: "new folder name",// there is no error here, even though it is obviously wrong},]);
Proposed solution
Change the AssetFolderModels.IModifyAssetFoldersData to be a discriminated union of available operations. Based on the op property, TypeScript would be able to identify what operation am I writing and would properly type-check them and offer me relevant IntelliSense. That would resolve both of the problems.
The type would look something like this:
exporttypeModifyAssetFoldersData=AddIntoOperation|RemoveOperation|RenameOperation;typeRemoveOperation={op: "remove";// ...};// define the rest of the operations
The text was updated successfully, but these errors were encountered:
There even is a bug, because the the of the value property is defined as IAddOrModifyAssetFolderData, which is an object with folder properties like name or folders. However, when I want to define the rename patch operation, I need to assign a string (the new name) into the value property (as per the documentation), but the type doesn't allow me to do so.
Motivation
When I want to modify asset folders, I have to specify patch operations. The SDK provides the
AssetFolderModels.IModifyAssetFoldersData
type for the operations. The problem is that this type doesn't guide me as to what properties are needed for different patch operations. I always have to check with the docs for what kind of properties I have to provide. It is unnecessarily difficult and opens up opportunities for mistakes. For example, when removing a folder I only have to specify thereference
property, but when renaming, I also have to specify thevalue
property.Properties also can have different types based on the operation type. For example, when renaming a folder, the
value
property has to be of typestring
(the new name), but when adding a folder, the same propertyvalue
has to be an object specifying the folder object.Example:
Proposed solution
Change the
AssetFolderModels.IModifyAssetFoldersData
to be a discriminated union of available operations. Based on theop
property, TypeScript would be able to identify what operation am I writing and would properly type-check them and offer me relevant IntelliSense. That would resolve both of the problems.The type would look something like this:
The text was updated successfully, but these errors were encountered: