包详细信息

class-without-call-parent-constructor

bluelovers1.6kMIT2.0.5

create class skip call parent constructor

create, class, extend, parent

自述文件

import classWithoutCallParentConstructor from 'class-without-call-parent-constructor';

describe(`describe`, () =>
{

    class A
    {
        constructor(a: any, b: any)
        {
            console.log("A.constructor");
            throw new Error('should not call A.constructor')
            a;
            b;
        }

        parentMethod()
        {
            console.log("A.parentMethod()");

            return "A.parentMethod()"
        }
    }

    test(`@ts-expect-error`, () =>
    {

        class B extends A
        {
            // @ts-expect-error
            constructor()
            {

            }
        }

        // @ts-ignore
        expect(() => new A).toThrowError();
        expect(() => new B).toThrowError();

    });

    test(`classWithoutCallParentConstructor`, () =>
    {
        class B extends classWithoutCallParentConstructor(A)
        {
            constructor()
            {
                super();
            }

            childMethod()
            {
                console.log("B.childMethod()");
                return "B.childMethod()"
            }
        }

        expect(() => new B).not.toThrowError();

        let actual = new B;

        expect(actual).toHaveProperty('parentMethod')
        expect(actual).toHaveProperty('childMethod')

        expect(actual.parentMethod()).toStrictEqual('A.parentMethod()')
        expect(actual.childMethod()).toStrictEqual('B.childMethod()')

    });

    test(`createNewTargetObject`, () =>
    {
        class B extends A
        {
            // @ts-ignore
            constructor()
            {
                return createNewTargetObject(new.target)
            }

            childMethod()
            {
                console.log("B.childMethod()");
                return "B.childMethod()"
            }
        }

        expect(() => new B).not.toThrowError();

        let actual = new B;

        expect(actual).toHaveProperty('parentMethod')
        expect(actual).toHaveProperty('childMethod')

        expect(actual.parentMethod()).toStrictEqual('A.parentMethod()')
        expect(actual.childMethod()).toStrictEqual('B.childMethod()')

    });

})

更新日志

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

2.0.4 (2021-07-01)

Note: Version bump only for package class-without-call-parent-constructor

2.0.3 (2021-07-01)

Note: Version bump only for package class-without-call-parent-constructor

2.0.2 (2021-06-30)

🐛 Bug Fixes

2.0.1 (2021-06-28)

🛠 Build System

⚙️ Continuous Integration

🔖 Miscellaneous

BREAKING CHANGE

  • update to es2019

1.0.2 (2021-06-28)

♻️ Chores

🔖 Miscellaneous

  • class-without-call-parent-constructor (c08a684)