Microsoft/TypeScript
Ver no GitHubUnable to infer parameters for generic constructor/functions with a distributive conditional type
Open
#62.079 aberto em 16 de jul. de 2025
BugDomain: Conditional TypesHelp Wanted
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
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
💻 Code
export {};
interface _Map {
foo: { a: 123 }
}
type ModuleSubType = "bar" & { brand: true };
type Map = _Map & Record<ModuleSubType, { blah: string }>
type SubTypeGet<
SubType extends string,
Map extends Record<SubType, unknown>,
> = 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<<T extends "foo" | ModuleSubType>(arg: SubTypeGet<T, Map>) => void>
// ^? never
// I originally encountered it with a class like this:
declare class Test<T extends "foo" | ModuleSubType> {
constructor(arg: SubTypeGet<T, Map>);
}
type TestConstructorParameters = ConstructorParameters<typeof Test>;
// ^? 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