Is there an equivalent to “sealed” or “final” in TypeScript?

后端 未结 3 505
慢半拍i
慢半拍i 2021-01-07 16:38

I\'m trying to implement a method in a super class that should be available for use, but not changeable, in sub classes. Consider this:

export abstract clas         


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 17:15

    // I use this workaround:
    
    export default class CreateHandler extends BaseHandler {
        // final prop used as method
        public readonly create = (blueprint: Blueprint): Response => {
            return blueprint.create();
        };
    
        // normal method
        public store(blueprint: Blueprint): Response {
            return this.response(blueprint.create());
        }
    }
    

提交回复
热议问题