Skip to content

TypeScript v4.5 regression: cannot use Parameters type on narrowed methods / functionsΒ #46855

Closed
@alecgibson

Description

@alecgibson

Bug Report

πŸ”Ž Search Terms

function, method, generic, parameters, does not satisfy constraint, 4.5

πŸ•— Version & Regression Information

  • This changed between versions 4.4.4 and 4.5.0

⏯ Playground Link

Playground link with relevant code

☝🏼 Switch the version to v4.4.4 and this compiles fine; v4.5.0-beta errors (as does v4.5.2, but the Playground doesn't offer this version)

πŸ’» Code

type Methods<T> = {
  [K in keyof T]: T[K] extends Function ? K : never;
}[keyof T];

class Test {
  foo = '';
  bar(a: string, b: number): void {}
}

function doSomeProxying<
  T,
  Method extends Methods<T>,
  Args extends Parameters<T[Method]>,
>(
  type: T,
  method: Method,
  ...args: Args
): void {}

doSomeProxying(new Test(), 'bar', 'arg', 123);

πŸ™ Actual behavior

Compiler errors in v4.5.0, even though it was fine in v4.4.4.

πŸ™‚ Expected behavior

Expect to be able to use the built-in Parameters<> type on properties I have narrowed down as functions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions