microsoft / microsoft/TypeScript

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

Open
#62,079 1 comment 0 reactions 0 assignees View on GitHub
Bug Domain: Conditional Types Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

### 🔎 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_

Contributor guide

Open the contributing guide

Research direction

Use the linked Playground reproduction as the first entry point; inspect how distributive conditional types flow through Parameters and ConstructorParameters for the generic function and constructor examples. Done means both utilities infer a non-never parameter tuple consistent with the expected behavior, with the existing reproduction no longer failing.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.