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
I suggest adding an operator (?) similar to extends which "extends but isn't". This would allow generics that define a specific string type "cm" or "mm". The actual operator name (referred to as extendsisnt in the example) is up for debate as I can't decide what it could be used for.
π Motivating Example
interfaceM<Textendsisnt string>extendsnumber{};// To keep types after function call rather than aliasingfunctionadd<Textendsisnt string>(a: M<T>,b: M<T>): M<T>{return(aasnumber)+(basnumber);}leta: M<"cm">=5;letb: M<"cm">=3;letc: M<"s">=4;add(a,b);// No error. Equivalent to:add<"cm">(a,b);add(a,c);// Should Error. "cm" != "s" and `T` can't be `string`// ^ This would be equivalent to `add<string>(a, c)` if `extends` was used in the function definition and would be allowed.
It is up for debate if aliases would count as "isn't"
interfacea{b: number;};interfacebextendsa{};typec=a;functiontest<Textendsisnta>(param: T): void{}leta: a;// Baseletb: b;// Extendsletc: c;// Aliastest(a)// Errors since a is `a`test(b)// No Error since b `extends` a and isn't `a`test(c)// ?? Possible error depending on if extendsisnt counts aliases as the same or different
π» Use Cases
Allowing ONLY subclasses/extensions of classes but not the classes themselves.
The text was updated successfully, but these errors were encountered:
How would you implement the measures example using #202?
The goal would be to allow type parameters that are nominal children of the string superclass. This would still require a extendsisnt would it not?
Edit: NVM. It seems like it might work depending on how the proposal works.
Suggestion
π Search Terms
Extends but isn't
extends parent but not parent
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
I suggest adding an operator (?) similar to
extends
which "extends but isn't". This would allow generics that define a specific string type "cm" or "mm". The actual operator name (referred to asextendsisnt
in the example) is up for debate as I can't decide what it could be used for.π Motivating Example
It is up for debate if aliases would count as "isn't"
π» Use Cases
Allowing ONLY subclasses/extensions of classes but not the classes themselves.
The text was updated successfully, but these errors were encountered: