microsoft / microsoft/TypeScript
Reusing function type with different parameters amount (overloading)
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Bug Report
Is there any reason it's not possible to re-use a function type that is overloaded aka has different possible amount of arguments?
In the playground I put some code that shows this issue, but I will put a quick snippet here:
declare function foo(c: {a: number; b: string}): void
declare function foo(a: number, b: string): void
foo({ a: 1, b: "2" })
foo(1, "2")
// This doesn't work but is relatively understandable
const bar1: typeof foo = (a_c, b) => {
a_c
b
}
// This should work, why it doesn't?
const bar2: typeof foo = (...args) => {
args
}
// it works fine, but you can't access the second parameter
const bar3: typeof foo = (a_c) => {
a_c
}
// it works fine, but you can't access the parameters
const bar4: typeof foo = () => {
}
bar2 in this example doesn't work, and the error that is given is Type '(args_0: number | { a: number; b: string; }, args_1: unknown) => void' is not assignable to type '{ (c: { a: number; b: string; }): void; (a: number, b: string): void; }'.
🔎 Search Terms
arguments overload parameter function
🕗 Version & Regression Information
In 4.4.0-beta & 4.3.5:

In 4.2.3 and before:

⏯ Playground Link
🙁 Actual behavior
It just errors out when trying to use "...args" to get all the possible arguments of the function
🙂 Expected behavior
To be able to use "...args" or similar to get the arguments and typescript to not complain just for trying to use it
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das Verhalten bei der Zuweisung von Überladungen im verlinkten TypeScript Playground mit den gemeldeten Versionen 4.3.5 und 4.4.0-beta zu reproduzieren. Vergleiche die akzeptierten und abgelehnten Beispiele und ermittle anschließend das beabsichtigte Verhalten für Implementierungen überladener Funktionen mit Rest-Parametern; abgeschlossen ist die Aufgabe, wenn das Verhalten und die erwartete Typisierung festgestellt und durch einen geeigneten Compiler-Test abgedeckt sind.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100