microsoft / microsoft/TypeScript
Unable to resolve generic type when using an overloaded function as parameter
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
🔎 Search Terms
overload parameter function
🕗 Version & Regression Information
Using the playground, the code works when I choose version 3.3.3. After that version, the problem comes up.
💻 Code
type SpecialType<T> = () => void & { value: T };
function specialFunction<T>(): SpecialType<T>;
function specialFunction<T>(source: Record<string, T>): Record<string, T>;
function specialFunction<T>(source?: Record<string, T>): SpecialType<T> | Record<string, T> {
return source as any;
}
const otherFunction = <K extends keyof T, T>(source: Record<string, T>, property: K): Record<string, T[K]> => ({ source, property }) as any;
const obj: Record<string, { label: string }> = { value: { label: 'hello world' } };
const defined = specialFunction(obj);
const working = otherFunction(defined, 'label');
const nonworking = otherFunction(specialFunction(obj), 'label');
const alsoworking = otherFunction(specialFunction<{ label: string }>(obj), 'label');
🙁 Actual behavior
The non-inlined call chain works and label is recognized as a property name. The inlined call as a parameter states, that the second parameter type is never(instead of keyof T).
🙂 Expected behavior
No different type resolution regardless of the call type.
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
Reproduziere das Beispiel im TypeScript playground mit Version 3.3.3 und einer späteren Version und vergleiche anschließend den inferierten Typ des zweiten Arguments in den beiden Aufrufen. Erledigt ist es, wenn der Inline-Aufruf 'label' konsistent mit dem nicht inline ausgeführten Aufruf akzeptiert, ohne das explizite generische Typargument zu erfordern.
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
- 30/100