@typescript-package/descriptor
Version:
A lightweight TypeScript library for property descriptor.
59 lines (58 loc) • 2.3 kB
TypeScript
/**
* @description
* @export
* @class Descriptors
* @template {object} Obj
* @template {keyof Obj} Keys
*/
export declare class Descriptors<Obj extends object, Keys extends keyof Obj> {
#private;
/**
* @description Accessor to get stored property descriptors.
* @returns The returned value is descriptors of map type.
*/
get descriptors(): Map<Keys, PropertyDescriptor>;
/**
* @description Creates an instance of `Descriptors` with obj and `keys` to pick descriptors.
* @param object An object from which descriptors are retrieved.
* @param keys Optional property keys to retrieve from specified `object`.
*/
constructor(object: Obj, ...keys: Keys[]);
/**
* @description Get property descriptor from `#descriptors`.
* @param key
* @returns
*/
get(key: Keys): PropertyDescriptor | undefined;
/**
* @description Get all descriptors from `#descriptors`.
* @returns The returned value is array of all stored descriptors.
*/
getAll(): Array<[Keys, PropertyDescriptor]>;
/**
* @description Check whether `#descriptors` has `key`.
* @param key The `key` to check whether descriptors has.
* @returns The returned value is a `boolean` indicating whether descriptors has descriptor of property `key`.
*/
has(key: Keys): boolean;
/**
* @description The method sets the `value` under `key` in `#descriptors`.
* @param key The property key to set descriptor.
* @param value Property descriptor to set under the `key`.
* @returns The returned value is an instance of `Descriptors`.
*/
set(key: Keys, value: PropertyDescriptor): this;
/**
* @description The method sets all descriptors from `object`.
// * @param object The object from which all descriptors are set.
* @returns The returned value is an instance of this.
*/
setAll<Key extends Keys>(): this;
/**
* @description The method sets descriptors from `object` of `keys`.
* @param object An object from which descriptors are set to `#descriptors`.
* @param keys Keys of `object` to retrieved descriptors.
* @returns The returned value is an instance of `Descriptors`.
*/
setPicked<Key extends Keys>(...keys: Key[]): this;
}