-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
First, thank you team for polymorphic this
. It is really handy!
I think I ran into a case though that I am finding challenging, when I need to return a this
, but the generics might have changed. For example:
class A<T> {
private items: T[] = [];
map<U>(callback: (item: T, idx: number, a: this) => U): this {
// boring implementation details
});
}
Where I want to be able to change the generic type for the class with a function, but I will be contracting to return the "current" class, but I want to guard different generics. The following seems logical to me, but doesn't appear to be currently supported:
class A<T> {
private items: T[] = [];
map<U>(callback: (item: T, idx: number, a: this) => U): this<U> {
// boring implementation details
});
}
Where if no generics arguments are supplied, it is inferred to be the current ones, where as if they are supplied they are substituted.
hesselink, niieani, tinganho, Pauan, kpdonn and 24 moresushruth
Metadata
Metadata
Assignees
Labels
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript