Next.js: type errors with ReferenceLinks
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 48/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- next.js, react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu với templates/next/components/ReferenceLinks.tsx và các chỗ sử dụng ReferenceLinks trong templates/next/components/foo/List.tsx và Show.tsx, sau đó tái hiện lỗi bằng docker compose exec pwa pnpm next build. So sánh các trường tùy chọn được tạo trong templates/next/types/foo.ts với bốn lỗi đã được báo cáo; hoàn tất khi ứng dụng Next.js được tạo có thể build mà không có các lỗi kiểu ReferenceLinks này.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
create-client version(s) affected: 0.10.0
Description
After generating an app in the pwa container derived from the standard distribution it works in the development environment but when running
docker compose exec pwa pnpm next build
i get the following type errors:
- ./components/employee/List.tsx employee["hours"] is possibly 'undefined'.
- the same error for ./components/employee/Show.tsx
- ./components/hours/List hours["employee"] Type '{ href: string; name: string | undefined; }' is not assignable to type 'string'
- The same error is in ./components/hours/Show.tsx
Causes:
- List component ReferenceLinks if isReferences (and isEmbeddeds?)
This happens because templates/next/types/foo.ts defines all properties as optional so that pwa/types/Employee.ts is generated to define hours like this:
public hours?: string[],
while on line 42-43 of templates/next/components/foo/List.tsx an undefined field is not addressed:
{{#if isReferences}}
<ReferenceLinks items={ {{{../lc}}}['{{{name}}}'].map((ref: any) => ({ href: getItemPath(ref, '/{{{lowercase reference.title}}}s/[id]'), name: ref })) } />
- Show component ReferenceLinks if isReferences (and isEmbeddeds?)
Like 1, on line 57-58 of templates/next/components/foo/Show.tsx
- List component ReferenceLinks if isReference (and isEmbedded?)
This happens because templates/next/types/foo.ts defines all properties as optional while
on line 44-45 of templates/next/components/foo/List.tsx an undefined field is not addressed:
{{else if reference}}
<ReferenceLinks items={ { href: getItemPath({{{../lc}}}['{{{name}}}'], '/{{{lowercase reference.title}}}s/[id]'), name: {{{../lc}}}['{{{name}}}'] } } />
- Show component ReferenceLinks if isReference (and isEmbedded?)
Similar to 3, line on line 57-58 of templates/next/components/foo/Show.tsx
How to reproduce
Clone MetaClass' Tutorial Api Platform repository using git:
git clone https://github.com/metaclass-nl/tutorial-api-platform.git
check out branch chapter2-next
start the containers with
docker compose up
The api container should execute the data base migrations automatically. If not do:
docker compose exec php ./bin/console doctrine:migrations:migrate
To clear the database and execute the fixtures enter the following command:
docker compose exec php bin/console doctrine:fixtures:load
Follow the instructions from readme.md. or point your browser to the same branch on github
and follow the instructions.
The paragraph "Checking types" describes how to reprocude this error as well as serveral others for wich seperate issues are created.
Possible Solution
The simpelest soloution is to change the type templates/next/components/ReferenceLinks.tsx
interface Props {
items:
to allow undefined items and item names.
Alternatively each of the values passed to items can be checked of undefined, like is done in paragraph "Checking types" of the readme of the tutorial branch chapter2-next
Additional Context
Api Platform version v3.1.3
typescript config see pnpm-lock.yaml and tsconfig.json
- Ngôn ngữ chính
- TypeScript
- Star
- 376
- Fork
- 132
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của api-platform/create-client
-
[potential Security Alert] New `test-vue-app` script added in `@api-platform/[email protected]`Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
api-platform/create-client#396 ·
-
[potential Security Alert] New `test-nuxt-app` script added in `@api-platform/[email protected]`Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
api-platform/create-client#397 ·
-
[potential Security Alert] New `test-next-app` script added in `@api-platform/[email protected]`Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
api-platform/create-client#395 ·
-
[potential Security Alert] New `test-react-app` script added in `@api-platform/[email protected]`Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
api-platform/create-client#394 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
api-platform/create-client#393 · 1 bình luận ·
Tất cả issue của api-platform/create-client
Issue tương tự
-
needs:triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ai-discovered
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
jessepollak/home#1627 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent-canvas bug llm priority:low ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
OpenHands/OpenHands#17806 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
radius-project/ai-extensions#923 ·
Maintainer thường phản hồi trong vòng 1 ngày