microsoft / microsoft/TypeScript
Type inference behaves unexpectedly when dealing with functions that have type parameters
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
When a function definition a with type parameters is passed as an argument to another function b, b is unable to destructure the parameters of the passed a function.
🔎 Search Terms
type parameter function argument destructure
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics
⏯ Playground Link
Playground link with relevant code
💻 Code
type DefaultVariantProps = {
tabsClassName?: string
}
function fn<P extends {}>(arg1?: (props: P) => void): P {
return null as any
}
const a = fn(null as any as (props: DefaultVariantProps) => void)
const b = fn(null as any as <T>(props: DefaultVariantProps) => void)
// no problem
a.tabsClassName
// Property 'tabsClassName' does not exist on type '{}'.(2339)
b.tabsClassName
type T1 = (props: DefaultVariantProps) => void
type T2 = <T>(props: DefaultVariantProps) => void
// no problem
type T3 = Parameters<T1>[0]['tabsClassName']
// no problem
type T4 = Parameters<T2>[0]['tabsClassName']
🙁 Actual behavior
When a function definition a with type parameters is passed as an argument to another function b, b is unable to destructure the parameters of the passed a function.
It seems that generics should not cause type inference failures.
🙂 Expected behavior
No error.
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 dem Codebeispiel und vergleiche die inferierten Typen von a und b, wenn die übergebene Funktion einen Typparameter hat. Das Issue ist abgeschlossen, wenn b.tabsClassName keinen Fehler erzeugt und der bestehende nicht-generische Fall weiterhin funktioniert.
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