microsoft / microsoft/TypeScript

Inconsistent error between different versions of the same function with required parameter following an optional one

Abierto
#57,565 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.4k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

🔎 Search Terms

error function optional required rest

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.5.0-dev.20240227#code/GYVwdgxgLglg9mABAIwIYCcAUqBciwgC2yApugDQoD8eBxZlEtRpFiAdJxgOYDOevKOhhhuAbQC6ASkQBvAL4AoRWnSKA9OsQA9KolCRYCFBmzN6bZDXwsGiJjYuVO7Hv0SDhoyVLwA3OBgAE2VVTABGKQBuRE1EAFEADwAHEmgSIMRUKEQAGxJUQUQAZiz0biISMCheSmQQHO44HPD2TAAmAFZuqWUDaHgkNAAvM0dWOus6CY4ucvcxB2m7FzcBIRFxCWk5JRVUYY0tXX1wAeMRseXLKds2JbvnOb51ry3fRADg0IOI6NitElUulMtk8gUiqUeJVqrUUA1EE0Wm0uj1FEA

💻 Code
function bar(a: number, b?: number, c: number, ...args: string[]) {}

bar
// ^? function bar(a: number, b?: number, c: number, ...args: string[]): void

bar(1); // Expected at least 3 arguments, but got 1.(2555)

function baz(a: number, b?: number, ...args: [c: number, ...args: string[]]) {}

baz
// ^? function baz(a: number, b?: number, c: number, ...args: string[]): void

baz(1); // Expected at least 3 arguments, but got 1.(2555)
🙁 Actual behavior

We get an error within the bar declaration ("'c' is declared but its value is never read.(6133)") but we get none in baz. They are pretty much equivalent.

🙂 Expected behavior

I'd expect this error to be raised consistently here (or not raised consistently).

In addition to that, b comes with the question mark in both quick infos here. TypeScript understands that at least 3 arguments are required here. It means that effectively b is required in both cases and ? is somewhat misleading here. I think it would be good to normalize this. It already is normalized with tuples:

type A = [a: number, b?: number, ...[c: number, ...args: string[]]]
//   ^? type A = [a: number, b: number | undefined, c: number, ...args: string[]]
Additional information about the issue

No response

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el ejemplo proporcionado de TypeScript Playground y compara los diagnósticos de bar y baz, incluidas sus firmas de quick-info. Se considera terminado decidir si el diagnóstico de parámetro no utilizado y la normalización de parámetros opcionales deben ser coherentes, y después añadir o actualizar la cobertura del compilador para el comportamiento elegido.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.