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
Cannot specify the type of an expression involving a Class returned from a function #43923
constq=<T>(x: T)=>classC{m=xconstructor(){}}constqa=new(q("2"))()// type is: q<string>.Cconstqb: q<string>.C=new(q("2"))()// Error// Note that this is also an issue with non polymorphic codeconstk=()=>classC{constructor(){}}constka=new(k())()// type is: Cconstkb: C=new(k())()// Error
🙁 Actual behavior
I can't explicitly type the expressions
🙂 Expected behavior
I would expect to be able to type this expression.
Ideally using the signature inferred by the compiler
Ryan Cavanaugh (@RyanCavanaugh) thanks for having taken the time to review this issue;
are all the ways to refer to this type enumerated above or do you know others? (or know where I can find others)
Thanks again!
Activity
naorzr commentedon May 3, 2021
It's possible to infer the type by doing
whzx5byb commentedon May 3, 2021
For non-polymorphic version:
Unfortunately it doesn't work in the polymorphic version, because ts doesn't support Generic Values.
There are some workarounds in https://stackoverflow.com/a/59072991/3016883 and https://stackoverflow.com/a/62724646/3016883
RyanCavanaugh commentedon May 3, 2021
constdoesn't create a new type; this is the intended behavior. There are many ways to refer to this type depending on what you want to do with it.ssledorze commentedon May 3, 2021
Ryan Cavanaugh (@RyanCavanaugh) thanks for having taken the time to review this issue;
are all the ways to refer to this type enumerated above or do you know others? (or know where I can find others)
Thanks again!
typescript-bot commentedon May 6, 2021
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.