-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Milestone
Description
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms:
bind this Generic classes
Code
interface FooFunction<Args extends any[]> {
(...args: Args): void;
}
export class Foo<Args extends any[]> {
private currentTimeout: number | undefined;
constructor(private readonly wrappedFunc: FooFunction<Args>) {
const originalFooCaller = this.fooCaller;
// Ideally you can leave out this line.
this.fooCaller = this.fooCaller.bind(this as ThisParameterType<typeof originalFooCaller>);
// Fails because it won't realize this and ThisParameterType<typeof originalFooCaller> are the same type
// I *think* because it won't resolve ThisParameterType until Args is known.
//this.fooCaller = this.fooCaller.bind(this);
}
fooCaller(...args: Args): void {
this.wrappedFunc.apply(undefined, args);
}
}
Expected behavior:
I don't need the explict cast to ThisParameterType
Actual behavior:
The ThisParameterType used by CallableFunction.bind doesn't match this.
Related Issues:
yishn
Metadata
Metadata
Assignees
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.