-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
π Search Terms
polymorphic this in static methods
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
π» Code
interface Ctor<T> {
prototype: T;
}
type InferCtorType<T> = T extends Ctor<infer R> ? R : never;
// Types
interface PromiseConstructor {
withResolvers<T>(): PromiseWithResolvers<T, this>;
}
interface Promise<T> {
withResolvers<T>(): PromiseWithResolvers<T, Ctor<this>>;
}
interface PromiseWithResolvers<T, TCtor = Ctor<Promise<T>>> {
promise: InferCtorType<TCtor>;
resolve(value: T): void;
reject(reason: unknown): void;
}
class CustomPromise<T> extends Promise<T> {
custom() { }
}
// Example
CustomPromise.withResolvers().promise.custom(); // <-- UNEXPECTED PromiseConstructor - must be typeof CustomPromise
new CustomPromise(() => null).withResolvers().promise.custom(); // <-- Works on instance methods
π Actual behavior
Polymorphic "this" in static methods is not resolved to actual type but instead resolves to definition time type.
π Expected behavior
Polymorphic "this" in static methods must resolve to proper subclass depending on the invocation.
Additional information about the issue
There was a similar bug reported #5863 but it is not talking specifically about the "this" type keyword which has the bug.
RyuuGan, privettoli and FRITS-Kh
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created