@typescript-package/descriptor
Version:
A lightweight TypeScript library for property descriptor.
95 lines (94 loc) • 7.67 kB
TypeScript
import { CommonDescriptor } from './common-descriptor.abstract';
import { ThisAccessorPropertyDescriptor } from '@typedly/descriptor';
import { ValidationCallback } from '@typedly/callback';
/**
* @description The `AccessorDescriptor` class is a concrete implementation of the `CommonDescriptor` class that represents an accessor property descriptor.
* @export
* @class AccessorDescriptor
* @template [O=any] The type of the object.
* @template {PropertyKey | keyof O} [K=keyof O] The type of property key.
* @template {K extends keyof O ? O[K] : any} [V=K extends keyof O ? O[K] : any] The type of value captured from the object.
* @template {boolean} [C=boolean] The type of the configurable property.
* @template {boolean} [E=boolean] The type of the enumerable property.
* @extends {CommonDescriptor<C, E>} Common descriptor properties.
*/
export declare class AccessorDescriptor<O = any, K extends PropertyKey | keyof O = keyof O, V extends K extends keyof O ? O[K] : any = K extends keyof O ? O[K] : any, C extends boolean = boolean, E extends boolean = boolean> extends CommonDescriptor<C, E> implements ThisAccessorPropertyDescriptor<V, O, C, E> {
/**
* @description Creates an instance of `AccessorDescriptor`.
* @public
* @static
* @template [O=any] The type of the object.
* @template {PropertyKey | keyof O} [K=keyof O] The type of property key.
* @template {K extends keyof O ? O[K] : any} [V=K extends keyof O ? O[K] : any] The type of value captured from the object.
* @template {boolean} [C=boolean] The type of the configurable property.
* @template {boolean} [E=boolean] The type of the enumerable property.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0 Accessor descriptor properties.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.configurable The type of configurable of `C`.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.enumerable The type of enumerable of `E`.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.get The type of the getter function.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.set The type of the setter function.
* @param {?O} [object] The object (non-stored) to define the descriptor on and capture the `this` context.
* @param {?K} [key] The (non-stored) key to define the descriptor on.
* @param {?ValidationCallback<ThisAccessorPropertyDescriptor<V, O, C, E>>} [onValidate]
* @returns {AccessorDescriptor<O, K, V, C, E>}
*/
static create<O = any, K extends PropertyKey | keyof O = keyof O, V extends K extends keyof O ? O[K] : any = K extends keyof O ? O[K] : any, C extends boolean = boolean, E extends boolean = boolean>({ configurable, enumerable, get, set }: ThisAccessorPropertyDescriptor<V, O, C, E>, object?: O, key?: K, onValidate?: ValidationCallback<ThisAccessorPropertyDescriptor<V, O, C, E>>): AccessorDescriptor<O, K, V, C, E>;
/**
* @description Returns strictly defined accessor descriptor of a `ThisAccessorPropertyDescriptor<V, O, C, E>` type on `get` or `set` property detected.
* @public
* @static
* @template [O=any] The type of the object.
* @template {PropertyKey | keyof O} [K=keyof O] The type of the object key.
* @template {K extends keyof O ? O[K] : any} [V=K extends keyof O ? O[K] : any] The type of the object value.
* @template {boolean} [C=boolean] The type of the configurable property.
* @template {boolean} [E=boolean] The type of the enumerable property.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0 The accessor descriptor attributes.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.configurable The configurable of `C` type.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.enumerable The configurable of `E` type.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.get The getter.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.set The setter.
* @param {?O} [object] The object (non-stored) to define the descriptor on and capture the `this` context.
* @param {?K} [key] The (non-stored) key to define the descriptor on and capture the type of value.
* @param {?ValidationCallback<ThisAccessorPropertyDescriptor<V, O, C, E>>} [onValidate] A `ValidationCallback` function to handle the result of the check whether the `descriptor` is an `object` with `get` or `set` property.
* @returns {(ThisAccessorPropertyDescriptor<V, O, C, E> | undefined)} The returned value is an `object` of a `ThisAccessorPropertyDescriptor<V, O, C, E>` type.
*/
static define<O = any, K extends PropertyKey | keyof O = keyof O, V extends K extends keyof O ? O[K] : any = K extends keyof O ? O[K] : any, C extends boolean = boolean, E extends boolean = boolean>({ configurable, enumerable, get, set }: ThisAccessorPropertyDescriptor<V, O, C, E>, object?: O, key?: K, onValidate?: ValidationCallback<ThisAccessorPropertyDescriptor<V, O, C, E>>): ThisAccessorPropertyDescriptor<V, O, C, E> | undefined;
/**
* @description Guards the `descriptor` to be an `object` of a `ThisAccessorPropertyDescriptor<V, O, C, E>` type.
* @public
* @static
* @template V The type of the value.
* @template O The type of the object.
* @template {boolean} [C=boolean] The type of the configurable.
* @template {boolean} [E=boolean] The type of the enumerable.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} descriptor The object of a `ThisAccessorPropertyDescriptor<V, O, C, E>` type to guard.
* @param {?ValidationCallback<ThisAccessorPropertyDescriptor<V, O, C, E>>} [callbackFn] A `ValidationCallback` function to handle the result of the check whether or not the descriptor is an `object` containing the `get` or `set` property.
* @returns {descriptor is ThisAccessorPropertyDescriptor<V, O, C, E>} The return value is a boolean indicating whether the `descriptor` is an `object` with the `get` or `set` property.
*/
static guard<V, O, C extends boolean = boolean, E extends boolean = boolean>(descriptor: ThisAccessorPropertyDescriptor<V, O, C, E>, callbackFn?: ValidationCallback<ThisAccessorPropertyDescriptor<V, O, C, E>>): descriptor is ThisAccessorPropertyDescriptor<V, O, C, E>;
/**
* @description The getter function.
* @public
* @type {?() => V}
*/
get?: () => V;
/**
* @description The setter function.
* @public
* @type {?(value: V) => void}
*/
set?: (value: V) => void;
/**
* Creates an instance of `AccessorDescriptor`.
* @constructor
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0 The properties of the accessor descriptor.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.configurable The configurable of generic type variable `C`.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.enumerable The enumerable of generic type variable `E`.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.get The getter function.
* @param {ThisAccessorPropertyDescriptor<V, O, C, E>} param0.set The setter function.
* @param {?O} [object] The object (non-stored) to define the descriptor on.
* @param {?K} [key] The (non-stored) key to define the descriptor on.
* @param {?ValidationCallback<ThisAccessorPropertyDescriptor<V, O, C, E>>} [onValidate]
*/
constructor({ configurable, enumerable, get, set }: ThisAccessorPropertyDescriptor<V, O, C, E>, object?: O, key?: K, onValidate?: ValidationCallback<ThisAccessorPropertyDescriptor<V, O, C, E>>);
}