microsoft / microsoft/TypeScript
Unexpected type infer for function first argument with default value since 5.1
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
"type infer first argument"
🕗 Version & Regression Information
- This is a crash
- This changed between versions v5.0.4 and v5.1.6
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
export type Factory<T> = (arg1: T, arg2: any) => any
export type Factory2<T> = (...args: [T, any]) => any
declare function infer1<T>(fn: Factory<T>): T
declare function infer2<T>(fn: Factory2<T>): T
const f1 = (msg: string = 'hello', test: any) => { }
const a1 = infer1(f1)
// ^? const a1: string | undefined
const a2 = infer2(f1)
// ^? const a2: string | undefined
const f2 = (msg: string = 'hello') => { }
const b = infer1(f2)
// ^? const b: string | undefined
const b1 = infer2(f2)
// ^? const b1: string | undefined
const c = infer1((msg: string = 'hello') => { })
// ^? const c: string
const c2 = infer2((msg: string = 'hello') => { })
// ^? const c2: string | undefined
🙁 Actual behavior
In my code you'll notice that the type of c is not the same as b, but the argument we passing into function infer1 is actually the same.
I've tested this between v5.0.4 and v5.1.6, but the type of c is different:
// v5.0.4
const c: string | undefined
// v5.1.6
const c: string
After checking v5.1 changelog, I'm still not sure what changes have been made between 5.0 to 5.1.
So I decided to submit this issue as a "Bug report".
🙂 Expected behavior
The type of c is supposed to be string | undefined.
Additional information about the issue
No response
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 mit dem verlinkten TypeScript Playground und reduziere die bereitgestellten Beispiele zur generischen Inferenz, während du TypeScript 5.0.4 mit 5.1.6 vergleichst. Verfolge das Verhalten der Typinferenz für standardmäßig gesetzte erste Parameter und ermittle, ob das gemeldete Ergebnis konsistent undefined enthalten sollte; abgeschlossen ist die Aufgabe, wenn das minimale Repro ohne Regressionen bei den verwandten Fällen dem erwarteten Typ entspricht.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100