microsoft / microsoft/TypeScript
Inconsistent error between different versions of the same function with required parameter following an optional one
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
🔎 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’esempio TypeScript Playground fornito e confronta le diagnosi per bar e baz, incluse le rispettive firme quick-info. Il lavoro è completato quando si è deciso se la diagnostica dei parametri inutilizzati e la normalizzazione dei parametri opzionali debbano essere coerenti, aggiungendo o aggiornando quindi la copertura del compilatore per il comportamento scelto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100