microsoft / microsoft/TypeScript
Inconsistent error between different versions of the same function with required parameter following an optional one
Nadie ha tomado este issue todavía.
- 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
💻 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
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.
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