Anyone currently rendering tree’s (outside of the core) in the new UI in Umbraco v16 (or maybe v15 too, as i have changed something)
I have a tree data source that follows the patterns in the core.
constructor(host: UmbControllerHost) {
super(host, {
getRootItems,
getChildrenOf,
getAncestorsOf,
mapper,
});
}
and for example the getRootItems method looks like this :
const getRootItems = async (args: UmbTreeRootItemsRequestArgs) => {
var data = await SetService.setTreeRoot({
query: {
skip: args.skip,
take: args.take,
},
});
return data;
};
now this works ! even though i get a typescript error when i build
getRootItems,
~~~~~~~~~~~~
node_modules/@umbraco-cms/backoffice/dist-cms/packages/core/tree/data/tree-server-data-source-base.d.ts:9:5
getRootItems: (args: TreeRootItemsRequestArgsType) => Promise<UmbDataSourceResponse<UmbPagedModel<ServerTreeItemType>>>;
~~~~~~~~~~~~
The expected type comes from property 'getRootItems' which is declared here on type
'UmbTreeServerDataSourceBaseArgs<TranslationTreeItemResponseModel,
TranslationTreeItemModel, UmbTreeRootItemsRequestArgs, UmbTreeChildrenOfRequestArgs,
UmbTreeAncestorsOfRequestArgs>'
src/section/tree/translations-tree.data-source.ts:23:4 - error TS2322: Type '(args: UmbTreeChildrenOfRequestArgs) => Promise<({ data: undefined; error: unknown; } | { data: PagedTranslationLanguageItemResponseModel; error: undefined; }) & { ...; }>' is not assignable to type '(args: UmbTreeChildrenOfRequestArgs) => Promise<UmbDataSourceResponse<UmbPagedModel<TranslationTreeItemResponseModel>>>'.
Type 'Promise<({ data: undefined; error: unknown; } | { data: PagedTranslationLanguageItemResponseModel; error: undefined; }) & { request: Request; response: Response; }>' is not assignable to type 'Promise<UmbDataSourceResponse<UmbPagedModel<TranslationTreeItemResponseModel>>>'.
Type '({ data: undefined; error: unknown; } | { data: PagedTranslationLanguageItemResponseModel; error: undefined; }) & { request: Request; response: Response; }' is not assignable to type 'UmbDataSourceResponse<UmbPagedModel<TranslationTreeItemResponseModel>>'.
Type '{ data: undefined; error: unknown; } & { request: Request; response: Response; }' is not assignable to type 'UmbDataSourceResponse<UmbPagedModel<TranslationTreeItemResponseModel>>'.
Types of property 'error' are incompatible.
Type 'unknown' is not assignable to type 'UmbError | UmbApiError | UmbCancelError | Error | undefined'
The summary of this is - it doesn’t like that heyApi is returning unknown for the error and now something structured.
I have marked up the method in the controller.
[HttpGet("TreeRoot")]
[ProducesResponseType<PagedViewModel<TranslationLanguageItemResponseModel>>(StatusCodes.Status200OK)]
[ProducesResponseType<ProblemDetails>(StatusCodes.Status400BadRequest)]
public ActionResult<PagedViewModel<TranslationLanguageItemResponseModel>> GetRoot(int skip = 0, int take = 100)
So gone around the houses, i am not sure if it’s heyApi. (v0.66.5) or its missing something on the return or marked it up somehow wrong.
I know its a bit of a pain because when i generate from my API i will make my own PageViewModel and it will not inherit this from the Core umbraco one (because heyAPI doesn’t know i am using the @umbraco/backoffice package.
but it all actually works in the client, so long way around of saying - anyone does this outside of the core with their own client api and not got these errors (on v16).
It was fine in v15 - but that was old heyApi client (not major old actually) , might just be a slight change in a definition somewhere in v16?