Next.js: type errors with ReferenceLinks
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- next.js, react, typescript
- Área
- frontend
Línea de trabajo
Comienza con templates/next/components/ReferenceLinks.tsx y los usos de ReferenceLinks en templates/next/components/foo/List.tsx y Show.tsx, y luego reproduce el fallo con docker compose exec pwa pnpm next build. Compara los campos opcionales generados en templates/next/types/foo.ts con los cuatro errores informados; se considera terminado cuando la aplicación Next.js generada se compila sin estos errores de tipos de ReferenceLinks.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- TypeScript
- Estrellas
- 376
- Forks
- 132
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de api-platform/create-client
-
[potential Security Alert] New `test-vue-app` script added in `@api-platform/client-generator@0.8.0` Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
api-platform/create-client#396 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 38/100
api-platform/create-client#397 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
api-platform/create-client#395 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
api-platform/create-client#394 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
api-platform/create-client#393 · 1 comentario ·
Todos los issues de api-platform/create-client
Issues similares
-
blocklist removal
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
MetaMask/eth-phishing-detect#296544 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
pastelsky/bundlephobia#1122 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100