From b248f878a14b94e114100e7936ffd4b63bcf5342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 28 Dec 2023 21:39:17 +0100 Subject: [PATCH] Added comments --- src/index.ts | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index f852ac8..9acfe8e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,13 +3,15 @@ import { AbstractClass, AbstractConstructor, Opaque, UnionToIntersection } from /** * Represents the static members of a class. - * - * @template C - The type of the class for which static members are extracted. - * @typeparam The static members of the class. + * @template C - The class type. */ export type StaticMembers = Pick +/** + * Represents a trait that can be applied to a class. + * @template C - The abstract class type. + */ export type Trait< C extends AbstractClass > = Opaque< @@ -17,17 +19,31 @@ export type Trait< "thilatrait/Trait" > +/** + * Represents the function signature for applying a trait to a parent class. + * @template C - The abstract class type. + */ export type TraitApplier< C extends AbstractClass > = (Parent: AbstractConstructor) => C +/** + * Unwraps the type of the class from a given trait. + * @template T - The trait type. + */ export type UnwrapTraitC = T extends Trait ? C : never +/** + * Creates a trait instance using the provided trait applier function. + * @template C - The abstract class type. + * @param applier - The trait applier function. + * @returns A trait instance. + */ export function trait< C extends AbstractClass >( @@ -37,6 +53,14 @@ export function trait< } +/** + * Extends a class with the given traits and expresses their combined functionality. + * @template C - The abstract class type. + * @template Traits - An array of trait instances. + * @param extend - The class to extend. + * @param traits - An array of trait instances to apply. + * @returns A new class type expressing the combined functionality of the base class and traits. + */ export function extendsAndExpresses< C extends AbstractClass, Traits extends readonly Trait[], @@ -72,6 +96,12 @@ export function extendsAndExpresses< ) } +/** + * Expresses the combined functionality of multiple traits. + * @template Traits - An array of trait instances. + * @param traits - An array of trait instances to apply. + * @returns A new class type expressing the combined functionality of the traits. + */ export function expresses< Traits extends readonly Trait[], >(