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
I'm mostly opening this issue to document the type errors below. For some of these, I'll open a PR and push the changes mentioned. Others are more involved and difficult to sort out.
There may be more type errors, also, but these were the ones I was able to work through in the last 4 or 5 hours. If I find more, I'll add them to the list.
Issues:
When running pnpm build in Next.js 14.0.4 I run into the following Type Errors:
1) Page "src/app/[[...paths]]/page.tsx" has an invalid "generateMetadata" export: Type GenerateMetadataParams is not valid.
This seems to be referring to wpUrl: string; in the type.
2) Type error: Object is possibly 'undefined'.
This is referring to the function getAllItems.
3) Type error: Object is possibly 'undefined'.
This is referring to the if branch in the function getAllItems.
4) Type error: Variable 'allData' implicitly has type 'any[]' in some locations where its type cannot be determined.
This one seems to be fixed by simply adding the Items type to allData.
5) Type error: 'menu' is possibly 'undefined'.
This one is referring to the fetch call using menus[0].
6) Type error: 'menu' is possibly 'undefined'.
This one is the same as above but in the error thrown.
7) Type error: 'err' is of type 'unknown'.
This one is a mystery to me, especially since it isn't throwing the error for the exact same line above it with menu.id instead of slug.
8) Type error: 'err' is of type 'unknown'.
This is the same as above in a different function, except that it seems to be solved when I try err as any.
9) Type error: Type 'SingleItem' is not assignable to type '{ data?: WpPage | undefined; previewData?: WpRevision | undefined; } | undefined'.
The first screenshot is of the console error, and the second is a prettified error message.
10) Type error: Object is possibly 'undefined'.
This one seems to be solved with the String() function and optional chaining for lines 42, 43, 52, and 54; and optional chaining for 46.
11) Type error: 'err' is of type 'unknown'.
This is the same as above in numbers 7 & 8, except that it seems to be solved when I try err as any.
12) Type error: 'postType' is possibly 'undefined'.
13) Type error: Property 'yoast_head_json' does not exist on type 'WpPage | ArchivePageData | TaxonomyPageData'.
14) Type error: Binding element 'postTypes' implicitly has an 'any' type.
This seems to be fixed when adding typing postTypes as string[].
15) Type error: Type 'number | undefined' is not assignable to type 'number'.
This seems to be solved by using the Number() function on line 25 and 51.
16) Type error: Object is possibly 'undefined'.
This one seems to be fixed with optional chaining.
17) Type error: Type 'undefined' cannot be used as an index type.
This one seems fixed by using the String() function.
18) Type error: 'matchingPostType' is possibly 'undefined'.
19) Type error: Binding element 'archiveSlug' implicitly has an 'any' type.
20) Type error: Object is possibly 'undefined'.
21) Type error: 'matchingPostType' is possibly 'undefined'.
22) Type error: Type '{ totalPages: number | undefined; totalItems: number | undefined; }' is not assignable to type '{ totalPages: number; totalItems: number; }'.
This one seems fixed by allowing totalPages and totalItems to be undefined on lines 142/143 and by using the Number() function in line 148.
23) Type error: 'err' is of type 'unknown'.
24) Type error: 'templates.archive' is possibly 'undefined'.
The text was updated successfully, but these errors were encountered:
I'm mostly opening this issue to document the type errors below. For some of these, I'll open a PR and push the changes mentioned. Others are more involved and difficult to sort out.
There may be more type errors, also, but these were the ones I was able to work through in the last 4 or 5 hours. If I find more, I'll add them to the list.
Issues:
When running
pnpm build
in Next.js 14.0.4 I run into the following Type Errors:1) Page "src/app/[[...paths]]/page.tsx" has an invalid "generateMetadata" export: Type
GenerateMetadataParams
is not valid.This seems to be referring to
wpUrl: string;
in the type.2) Type error: Object is possibly 'undefined'.
This is referring to the function
getAllItems
.3) Type error: Object is possibly 'undefined'.
This is referring to the if branch in the function
getAllItems
.4) Type error: Variable 'allData' implicitly has type 'any[]' in some locations where its type cannot be determined.
This one seems to be fixed by simply adding the
Items
type toallData
.5) Type error: 'menu' is possibly 'undefined'.
This one is referring to the fetch call using
menus[0]
.6) Type error: 'menu' is possibly 'undefined'.
This one is the same as above but in the error thrown.
7) Type error: 'err' is of type 'unknown'.
This one is a mystery to me, especially since it isn't throwing the error for the exact same line above it with
menu.id
instead ofslug
.8) Type error: 'err' is of type 'unknown'.
This is the same as above in a different function, except that it seems to be solved when I try
err
asany
.9) Type error: Type 'SingleItem' is not assignable to type '{ data?: WpPage | undefined; previewData?: WpRevision | undefined; } | undefined'.
The first screenshot is of the console error, and the second is a prettified error message.
10) Type error: Object is possibly 'undefined'.
This one seems to be solved with the String() function and optional chaining for lines 42, 43, 52, and 54; and optional chaining for 46.
11) Type error: 'err' is of type 'unknown'.
This is the same as above in numbers 7 & 8, except that it seems to be solved when I try
err
asany
.12) Type error: 'postType' is possibly 'undefined'.
13) Type error: Property 'yoast_head_json' does not exist on type 'WpPage | ArchivePageData | TaxonomyPageData'.
14) Type error: Binding element 'postTypes' implicitly has an 'any' type.
This seems to be fixed when adding typing postTypes as
string[]
.15) Type error: Type 'number | undefined' is not assignable to type 'number'.
This seems to be solved by using the Number() function on line 25 and 51.
16) Type error: Object is possibly 'undefined'.
This one seems to be fixed with optional chaining.
17) Type error: Type 'undefined' cannot be used as an index type.
This one seems fixed by using the String() function.
18) Type error: 'matchingPostType' is possibly 'undefined'.
19) Type error: Binding element 'archiveSlug' implicitly has an 'any' type.
20) Type error: Object is possibly 'undefined'.
21) Type error: 'matchingPostType' is possibly 'undefined'.
22) Type error: Type '{ totalPages: number | undefined; totalItems: number | undefined; }' is not assignable to type '{ totalPages: number; totalItems: number; }'.
This one seems fixed by allowing
totalPages
andtotalItems
to be undefined on lines 142/143 and by using the Number() function in line 148.23) Type error: 'err' is of type 'unknown'.
24) Type error: 'templates.archive' is possibly 'undefined'.
The text was updated successfully, but these errors were encountered: