Function Final

  • Marks a class as final, preventing inheritance from this class. When applied, any attempt to extend this class will result in a TypeError at runtime.

    Type Parameters

    Parameters

    Returns CST

    Remarks

    This decorator does not prevent instantiation of the final class itself.

    Example

    @Final
    class Foo<T> {
    foo: T;
    bar: string;

    constructor(foo: T) {
    this.foo = foo;
    this.bar = 'bar';
    }

    someFoo(): T {
    return this.foo;
    }
    }

    // No problem with instantiation
    const foo = new Foo<string>('foo');

    // The line below will cause a TypeError: Cannot inherit from the final class Foo
    const sub = new SubFoo('subFoo');

    See