Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bluelovers/class-without-call-parent-constructor
create class skip call parent constructor
https://github.com/bluelovers/class-without-call-parent-constructor
Last synced: 3 days ago
JSON representation
create class skip call parent constructor
- Host: GitHub
- URL: https://github.com/bluelovers/class-without-call-parent-constructor
- Owner: bluelovers
- License: mit
- Created: 2021-06-27T23:51:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-08-30T20:05:48.000Z (about 2 years ago)
- Last Synced: 2024-10-12T03:23:11.820Z (about 1 month ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
```typescript
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()')});
})
```