You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Prefix <T> to access methods with generics : Klass[<T>"method"]Β #57297
Nope.
You didn't "access a method with generics from a class" in TS, but asked the type of a value that happens to be a method.
classKlass{method<T>(){}}// from the classtypeT=Klass;typem1=T["method"]// from the type of the classtypeTK=typeofKlass;typem2=TK["prototype"]["method"];
Nope. You didn't "access a method with generics from a class" in TS, but asked the type of a value that happens to be a method.
I don't understand what you're getting at here. whzx5byb's answer isn't even a workaround; it's a solution.
I also don't see what this being in a class has to do with anything. There are existing issues around generic instantiation of a type as opposed to a value.
I also don't see what this being in a class has to do with anything. There are existing issues around generic instantiation of a type as opposed to a value.
My suggestion wasn't about generic instantiation of a type, but to be able to fetch a generic version of a method.
It is not (2 operations) :
operator []: we fetch Klass["method"]
operator <>: we make a generic instantiation of the returned type.
But (1 operation):
operator [<> ]: we fetch Klass[<T>"method"] directly as a type.
Sorry if I'm not clear in my expression, I am not quite familiar with TS nomenclature and internal stuff.
I then suggested an extension to the syntax for a more generic usage, that is indeed a generic instantiation of a type.
Which would give (in the same case as above): <T>(Klass["method"]). So it is slightly different.
I made another issue as other issues doesn't seem active / followed.
I think I suggested a way that seems to not have the drawback of other cited suggestions:
no syntax ambiguity (?)
simple, clear and concise syntax.
I guess not too much trouble to implement (?).
Nope. You didn't "access a method with generics from a class" in TS, but asked the type of a value that happens to be a method.
I don't understand what you're getting at here. whzx5byb's answer isn't even a workaround; it's a solution.
It isn't, as he gets the type from a value that happens to be a method, not from the class in TS.
When manipulating types, there are lot of cases where you don't have access to the values :
functionfoo<TextendsRecord<string,X>>(...){typeT2<U>={[KinkeyofT]: T[K][<U>"method"]// can't have access to the class value as we are in TS (type manipulation, not value manipulation).}}
Activity
whzx5byb commentedon Feb 5, 2024
Workaround: access method from
prototype.denis-migdal commentedon Feb 5, 2024
Nope.
You didn't "access a method with generics from a class" in TS, but asked the type of a value that happens to be a method.
Your solution could work using functions :
But due to Typescript widening, that will return
BaseClass.prototype.method<U>instead ofT.prototype.method<U>cf #57286
Also, we could help TS by precising the return type :
But we have currently no ways to precise the generic parameters to the type...
RyanCavanaugh commentedon Feb 5, 2024
I don't understand what you're getting at here. whzx5byb's answer isn't even a workaround; it's a solution.
I also don't see what this being in a class has to do with anything. There are existing issues around generic instantiation of a type as opposed to a value.
denis-migdal commentedon Feb 5, 2024
My suggestion wasn't about generic instantiation of a type, but to be able to fetch a generic version of a method.
It is not (2 operations) :
[]: we fetchKlass["method"]<>: we make a generic instantiation of the returned type.But (1 operation):
[<> ]: we fetchKlass[<T>"method"]directly as a type.Sorry if I'm not clear in my expression, I am not quite familiar with TS nomenclature and internal stuff.
I then suggested an extension to the syntax for a more generic usage, that is indeed a generic instantiation of a type.
Which would give (in the same case as above):
<T>(Klass["method"]). So it is slightly different.I made another issue as other issues doesn't seem active / followed.
I think I suggested a way that seems to not have the drawback of other cited suggestions:
It isn't, as he gets the type from a value that happens to be a method, not from the class in TS.
When manipulating types, there are lot of cases where you don't have access to the values :
typescript-bot commentedon Feb 8, 2024
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.