Next.js: type errors with ReferenceLinks
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- next.js, react, typescript
- 領域
- frontend
調査の方向性
templates/next/components/ReferenceLinks.tsx と、templates/next/components/foo/List.tsx および Show.tsx にある ReferenceLinks の使用箇所から始め、docker compose exec pwa pnpm next build で失敗を再現します。templates/next/types/foo.ts に生成されたオプショナルフィールドを、報告された4つのエラーと比較します。生成された Next.js アプリがこれらの ReferenceLinks の型エラーなしでビルドできれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- TypeScript
- スター
- 376
- フォーク
- 132
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/create-client のほかの issue
-
[potential Security Alert] New `test-vue-app` script added in `@api-platform/client-generator@0.8.0` オープン
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/create-client#396 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 38/100
api-platform/create-client#397 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
api-platform/create-client#395 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/create-client#394 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
api-platform/create-client#393 · コメント 1 件 ·
api-platform/create-client の issue をすべて見る
似ている issue
-
VerificationGate: ATTRIBUTION quote guard never matches a normal quotation (\b around the quote) オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
danielmiessler/LifeOS#2234 ·
-
T: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
Mend: dependency security vulnerability untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100