microsoft / microsoft/TypeScript

Unable to infer parameters for generic constructor/functions with a distributive conditional type

Offen
#62,079 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug Domain: Conditional Types Help Wanted
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

### 🔎 Search Terms

generic constructor, generic function, branded string, `ConstructorParameters`, `Parameters`, unable to infer.

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ

### ⏯ Playground Link

https://www.typescriptlang.org/play/?#code/KYDwDg9gTgLgBAbwL4G4CwAoTBLAdjYKAMwEMBjYOAfQFkSxFM44iIIAuROEzgRgCYAzHCSZRWDDACeYSjQgATAK4AbYAGUlAIwAqMygF44AIi0koxuADIuWqCVwLOMKEsqpMmabLh0GR2nprOAAlYDJoBQAeeWU1TV19ABpbFRIAC04AZxc8AHMRAD5PSX04BL1ZAHFgGCimcu1KylACRyy4HKh8pIa-OFbgdtDwyKiK5LglXABrXAgAd1xC3oxCuCMJn0Hh6bnF3EwAfi5vYCPOLfdgvwBtK4BdTE5cYAA3QnQJAHpvuB10tgOkC4DB0pQALYQHKdFwkbB5dIwVhQBbmBRwNFSOAASTgZAcLARSiglAgSngMAg+IgEMoVNBgOBWSybnYXjKOmAOQACuYSHSCFAOkY+fZBYQslEojoBiA2goOsZWBBLAAfXyKVQaJr6QoACnMeUuuuqtRlKT8hQAlBt1m8INgFMUML9mHAAHonV4fKAlN146AIvAkFQqbFDCLTIXADHYeALePpbj4tIsuAqbAzelM9kYBThNKk1MkdNcnIyuUKpUq9WauI6xKydYIBoRXBdJRkKlQQ1QY2NJvAGp1HSW+g2r7iDk+cswADCEA7Li7PbFAtqko2cEXy9c3eg64lwqiZwgRH+3JghS+buYXrgPsIQA

### 💻 Code

```ts
export {};

interface _Map {
foo: { a: 123 }
}

type ModuleSubType = "bar" & { brand: true };

type Map = _Map & Record

type SubTypeGet<
SubType extends string,
Map extends Record,
> = SubType extends unknown
? { type?: SubType } & Map[SubType]
: never;

// This is the most straightforward way I can figure out to come to this issue:
type TestParameters = Parameters<(arg: SubTypeGet) => void>
// ^? never

// I originally encountered it with a class like this:
declare class Test {
constructor(arg: SubTypeGet);
}

type TestConstructorParameters = ConstructorParameters;
// ^? never
```

### 🙁 Actual behavior

`Parameters` fails to infer anything.

### 🙂 Expected behavior

`Parameters` should infer _something,_ probably `[arg: { type?: ModuleSubType | undefined; } | ({ type?: "foo" | undefined; } & { a: 123; })]` as it would if the function/class were instantiated.

### Additional information about the issue

_No response_

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Verwende die verknüpfte Playground-Reproduktion als ersten Einstiegspunkt; untersuche, wie distributive bedingte Typen bei den generischen Funktions- und Konstruktorbeispielen durch Parameters und ConstructorParameters fließen. Erledigt ist die Aufgabe, wenn beide Utilities ein nicht-never-Parameter-Tupel entsprechend dem erwarteten Verhalten inferieren und die vorhandene Reproduktion nicht mehr fehlschlägt.

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
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.