CalebBarnes/nextwp

Type Errors in Build

Opened this issue · 1 comments

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.

Screenshot from 2024-03-22 00-02-22

2) Type error: Object is possibly 'undefined'.
This is referring to the function getAllItems.

Screenshot from 2024-03-21 23-04-22

3) Type error: Object is possibly 'undefined'.
This is referring to the if branch in the function getAllItems.

Screenshot from 2024-03-21 23-08-33

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.

Screenshot from 2024-03-21 23-09-31

5) Type error: 'menu' is possibly 'undefined'.
This one is referring to the fetch call using menus[0].

Screenshot from 2024-03-21 23-11-11

6) Type error: 'menu' is possibly 'undefined'.
This one is the same as above but in the error thrown.

Screenshot from 2024-03-21 23-12-48

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.
Screenshot from 2024-03-21 23-14-25

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.
Screenshot from 2024-03-21 23-20-38

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.

Screenshot from 2024-03-21 23-22-49
Screenshot from 2024-03-21 23-23-43

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.
Screenshot from 2024-03-21 23-25-56

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.
Screenshot from 2024-03-21 23-54-08

12) Type error: 'postType' is possibly 'undefined'.

Screenshot from 2024-03-21 23-56-29

13) Type error: Property 'yoast_head_json' does not exist on type 'WpPage | ArchivePageData | TaxonomyPageData'.

Screenshot from 2024-03-22 00-06-39

14) Type error: Binding element 'postTypes' implicitly has an 'any' type.
This seems to be fixed when adding typing postTypes as string[].
Screenshot from 2024-03-22 00-09-35

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.
Screenshot from 2024-03-22 00-14-45

16) Type error: Object is possibly 'undefined'.
This one seems to be fixed with optional chaining.

Screenshot from 2024-03-22 00-16-44

17) Type error: Type 'undefined' cannot be used as an index type.
This one seems fixed by using the String() function.
Screenshot from 2024-03-22 00-17-45

18) Type error: 'matchingPostType' is possibly 'undefined'.

Screenshot from 2024-03-22 00-18-50

19) Type error: Binding element 'archiveSlug' implicitly has an 'any' type.

Screenshot from 2024-03-22 01-32-37

20) Type error: Object is possibly 'undefined'.

Screenshot from 2024-03-22 01-33-19

21) Type error: 'matchingPostType' is possibly 'undefined'.

Screenshot from 2024-03-22 01-34-58

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.
Screenshot from 2024-03-22 01-36-36

23) Type error: 'err' is of type 'unknown'.

Screenshot from 2024-03-22 01-40-33

24) Type error: 'templates.archive' is possibly 'undefined'.

Screenshot from 2024-03-22 01-41-31

25) Type error: Object is possibly 'undefined'.

Screenshot from 2024-03-22 09-38-39

26) Type error: Object is possibly 'undefined'.

Screenshot from 2024-03-22 09-42-40

As far as I can tell, these are the only type errors I'm getting from @nextwp/core.