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
However it is not good: the type parameter Member is not exactly SomeMember<A, B, C, D>, so you cannot use an instance of SomeMember<A, B, C, D> for Member, esp. if it is overwritten by the user.
It should work nicely if it is declared inside the class:
classSomeGenericClass<A,B,C,D,E,F,G>{typeMember=SomeMember<A,B,C,D>// or: type Member: SomeMember<A, B, C, D>member1: Membermember2: Member// or even in the constructor (which may prevent type inferencing, but let's see)constructor(arg: Member){this.member1=argthis.member2=arg}}
It may also be used outside the class:
...
typeFoo=SomeGenericClass<A,B,C,D,E,F,G>.Member// which equals SomeMember<A, B, C, D>// orconstsomeInstance=newSomeGenericClass(arg);typeFoo2=(typeofsomeInstance).Member
π Motivating Example
To simplify and clarify complex generic classes.
π» Use Cases
What do you want to use this for?
In complex generic classes.
What shortcomings exist with current approaches?
Have to repeat myself again and again.
What workarounds are you using in the meantime?
By repeating myself.
The text was updated successfully, but these errors were encountered:
π Search Terms
member type, type alias, generic
β Viability Checklist
β Suggestion
When implementing a generic class with typescript, some types with very long type parameter list may be reused very frequently, eg:
It would be nice if those types can be aliased somewhere. This type alias could not be outside the class or the type parameter would be lost:
Or it could be:
However it is not good: the type parameter Member is not exactly
SomeMember<A, B, C, D>
, so you cannot use an instance ofSomeMember<A, B, C, D>
forMember
, esp. if it is overwritten by the user.It should work nicely if it is declared inside the class:
It may also be used outside the class:
π Motivating Example
To simplify and clarify complex generic classes.
π» Use Cases
In complex generic classes.
Have to repeat myself again and again.
By repeating myself.
The text was updated successfully, but these errors were encountered: