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
There should be a mechanism to mark classes and methods final, as in if a class is final, then one cannot subclass it, also, if a method is final, one should not be able to override it in the subclass.
There were many requests for the TypeScript team to implement this feature, check this, this and this, well since they haven't introduced it I doubt they ever will.
Now about final classes, the library already has a final class decorator and it works as intended, check it out here.
The problem is with a @finalMethod decorator implementation. I Haven't found a way to implement this feature yet.
New feature description
Something like
import{finalMethod}from'ts-roids';importtype{NewType}from'ts-roids';typeBar=NewType<'Bar',string>;abstractclassBaseFoo<T>{abstractsomeFoo(): T;}classFoo<T>extendsBaseFoo<T>{foo: T;bar: Optional<string>;constructor(foo: T,bar?: string){super();this.foo=foo;this.bar=bar??null;}overridesomeFoo(): T{returnthis.foo;}
@finalMethodsomeBar(): Bar{return'bar'asBar}}classSubFooextendsFoo<string>{constructor(foo: string){super(foo);}overridesomeBar(): Bar{// This should not be possible return'not bar'asBar}}// No problem with instantiation of `Foo`constfoo=newFoo<string>('foo');// The line below SHOULD cause a TypeError upon instantiation: Cannot override the final method 'someBar'...constsub=newSubFoo('subFoo');/* Now if instantiation is allowed because of a decorator limitation, then a TypeError should be thrown when attempting to use the method somehow, like this: */constnotBar=sub.someBar()// SHOULD throw: TypeError: Cannot override the final method 'someBar'...
New feature implementation
Well nothing worked yet.
The text was updated successfully, but these errors were encountered:
New feature motivation
There should be a mechanism to mark classes and methods
final
, as in if a class is final, then one cannot subclass it, also, if a method is final, one should not be able to override it in the subclass.There were many requests for the TypeScript team to implement this feature, check this, this and this, well since they haven't introduced it I doubt they ever will.
Now about final classes, the library already has a final class decorator and it works as intended, check it out here.
The problem is with a
@finalMethod
decorator implementation. I Haven't found a way to implement this feature yet.New feature description
Something like
New feature implementation
Well nothing worked yet.
The text was updated successfully, but these errors were encountered: