Skip to content

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

@LukeAbby

Description

@LukeAbby

πŸ”Ž 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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions