20231230.0.0 #6
23
src/index.ts
23
src/index.ts
@@ -53,6 +53,9 @@ export type UnwrapTraitC<T> =
|
|||||||
* static readonly defaultPermissions: string[] = []
|
* static readonly defaultPermissions: string[] = []
|
||||||
* permissions: string[] = []
|
* permissions: string[] = []
|
||||||
*
|
*
|
||||||
|
* // Constructor is optional
|
||||||
|
* // If you wish to use it, make sure it takes any[] as an args array and passes it to the super call. This is necessary for inheritance to work properly.
|
||||||
|
* // Trait constructors cannot have typed arguments of their own, they only serve to run logic during object instantiation.
|
||||||
* constructor(...args: any[]) {
|
* constructor(...args: any[]) {
|
||||||
* super(...args)
|
* super(...args)
|
||||||
* }
|
* }
|
||||||
@@ -72,6 +75,7 @@ export type UnwrapTraitC<T> =
|
|||||||
* return this.id === el.id
|
* return this.id === el.id
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
|
* // Optional
|
||||||
* constructor(...args: any[]) {
|
* constructor(...args: any[]) {
|
||||||
* super(...args)
|
* super(...args)
|
||||||
* }
|
* }
|
||||||
@@ -80,6 +84,25 @@ export type UnwrapTraitC<T> =
|
|||||||
* return Identifiable
|
* return Identifiable
|
||||||
* })
|
* })
|
||||||
* ```
|
* ```
|
||||||
|
* Creates a subtrait:
|
||||||
|
* ```ts
|
||||||
|
* const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
||||||
|
* trait(Parent => {
|
||||||
|
* abstract class ImplementsIdentifiable extends extendsAndExpresses(
|
||||||
|
* Parent,
|
||||||
|
* [Identifiable<ID>()],
|
||||||
|
* ) {
|
||||||
|
* id: ID = defaultID
|
||||||
|
*
|
||||||
|
* // Optional
|
||||||
|
* constructor(...args: any[]) {
|
||||||
|
* super(...args)
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* return ImplementsIdentifiable
|
||||||
|
* })
|
||||||
|
* ```
|
||||||
*/
|
*/
|
||||||
export function trait<
|
export function trait<
|
||||||
C extends AbstractClass<any>
|
C extends AbstractClass<any>
|
||||||
|
|||||||
@@ -21,7 +21,10 @@ const Identifiable = <ID>() =>
|
|||||||
|
|
||||||
const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
const ImplementsIdentifiable = <ID>(defaultID: ID) =>
|
||||||
trait(Parent => {
|
trait(Parent => {
|
||||||
abstract class ImplementsIdentifiable extends extendsAndExpresses(Parent, [Identifiable<ID>()]) {
|
abstract class ImplementsIdentifiable extends extendsAndExpresses(
|
||||||
|
Parent,
|
||||||
|
[Identifiable<ID>()],
|
||||||
|
) {
|
||||||
id: ID = defaultID
|
id: ID = defaultID
|
||||||
|
|
||||||
constructor(...args: any[]) {
|
constructor(...args: any[]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user