I'm puzzled by this error message mentioning null. Doesn't seo?.breadcrumbs || []
already handle the case where breadcrumbs
is null?
When I use as SEOPostTypeBreadcrumbs[]
in Intro Props, it resolves the issue, but it feels like a temporary fix.
EDIT: It seems to be pointing out that items in the array of breadcrumbs
may sometimes be null? This was auto-generated by Wordpress GraphQL tool graphql-codegen
TS2322: Type 'Maybe<{ __typename?: "SEOPostTypeBreadcrumbs" | undefined; }
& Pick<SeoPostTypeBreadcrumbs, "text" | "url">>[]' is not assignable to type 'SeoPostTypeBreadcrumbs[]'.
Type 'Maybe<{ __typename?: "SEOPostTypeBreadcrumbs" | undefined; } & Pick<SeoPostTypeBreadcrumbs, "text" | "url">>'
is not assignable to type 'SeoPostTypeBreadcrumbs'.
Type 'null' is not assignable to type 'SeoPostTypeBreadcrumbs'.
intro.tsx(28, 5): The expected type comes from property 'breadcrumbs' which is declared here on type 'IntrinsicAttributes & IntroProps'
seo
type:
export type CptNeighborhoodFragment = { __typename: 'CptNeighborhood' } & {
seo?: Maybe<
{ __typename?: 'PostTypeSEO' } & Pick<
PostTypeSeo,
| 'metaDesc'
| 'metaKeywords'
| 'metaRobotsNofollow'
| 'metaRobotsNoindex'
| 'opengraphAuthor'
| 'opengraphDescription'
| 'title'
> & {
breadcrumbs?: Maybe<
Array<
Maybe<
{ __typename?: 'SEOPostTypeBreadcrumbs' } & Pick<
SeoPostTypeBreadcrumbs,
'text' | 'url'
>
>
>
>;
}
>;
};
Usage:
<Intro
title={seo?.title || ''}
breadcrumbs={seo?.breadcrumbs || []}
/>
Intro Props
interface IntroProps {
title: string;
breadcrumbs?: SeoPostTypeBreadcrumbs[];
}
SeoPostTypeBreadcrumbs
export type SeoPostTypeBreadcrumbs = {
__typename?: 'SEOPostTypeBreadcrumbs';
text?: Maybe<Scalars['String']>;
url?: Maybe<Scalars['String']>;
};