The intersection XXX was reduced to never because property contentType has conflicting types in some constituents
Description
I have an issue with the intersections being created rather than unions.
The intersection HomeContentResponseModel was reduced to never because property contentType has conflicting types in some constituents.
I'm getting this error recently when using this library with Umbraco.
export type HomeContentModel = IApiContentModelBase & {
contentType: 'home';
} & {
properties?: HomePropertiesModel;
};
export type HomeContentResponseModel = IApiContentResponseModelBase & {
contentType: 'home';
} & HomeContentModel;
export type HomePropertiesModel = {
title?: string | null;
};
Reproducible example or configuration
https://github.com/garpunkal/umbraco-headless-starter/blob/main/src/content-delivery/openapi-ts.config.ts
https://github.com/garpunkal/umbraco-headless-starter/tree/main/src/content-delivery/src/scripts/api
OpenAPI specification (optional)
https://gist.github.com/garpunkal/b75a824d132d9fe2e8f386dcf3d58f6c
System information (optional)
No response
@garpunkal I had a look and it's not clear to me what the correct output would be here, there's a lot going on in that spec haha. What was the output in the previous version and which version was that? What do you expect the output to look like?
This is the error I get when trying to use this method, and I believe it's because the output of the generated TS, has this:
public async getContentItemByPath(path: string): Promise<IApiContentResponseModel> {
const item = await ContentService.getContentItemByPath20({
path: { path: path },
client: this.client,
headers: {
"Api-Key": this.config.apiKey,
preview: this.config.preview
},
query: {
expand: "properties[content[properties[$all]],$all]"
}
});
return item.data;
}
export type HomeContentModel = IApiContentModelBase & {
contentType: 'home';
} & {
properties?: HomePropertiesModel;
};
export type HomeContentResponseModel = IApiContentResponseModelBase & {
contentType: 'home';
} & HomeContentModel;
export type HomePropertiesModel = {
title?: string | null;
};
Just to add to this using "orval" as the sdk generation tool you don't get the never error, its generation is slightly different.
e.g. for my Homepage response it does
export type HomePageContentResponseModel = Omit<IApiContentResponseModelBase & HomePageContentModel, 'contentType'> & {
contentType: HomePageContentResponseModelContentType;
};
export const HomePageContentResponseModelContentType = {
homePage: 'homePage',
} as const;
whereas heyapi it does
export type HomePageContentResponseModel = IApiContentResponseModelBase & {
contentType: 'homePage';
} & HomePageContentModel;
Maybe having it omit contentType as part of the generation will be something that can be looked into?
EDIT: Just tested manually omitting contentType in the heyapi gen files e.g.
export type HomePageContentResponseModel = Omit<IApiContentResponseModelBase & HomePageContentModel, 'contentType'> & {
contentType: 'homePage';
};
And the reduced to never is gone and types are working correctly, however this does show then further areas which need changing
Hi @mrlubos does the above give enough info to remove the "needs info" label? Let me know if any further info is required.
My use case is the same as @garpunkal where the Swagger file is generated by Umbraco's Content Delivery API (so that cannot be altered) and then using the latest hey-api to generate a SDK.
Oh yes, sorry I forgot to remove the label
thanks @millnut for helping.