UNPKG

@boristype/types

Version:

<h1 align="center">WT Types</h1> <div align="center"> Typescript типы для WebSoft HCM.

200 lines (173 loc) 8.35 kB
/** * Конструктор объекта javascript. * * Создает новый объект. * * По умолчанию для объекта определен атрибуты и методы: * - {@link HasProperty} * - {@link AddProperty} * - {@link SetProperty} * - {@link GetProperty} * - {@link GetOptProperty} */ interface Object { [key: string | number]: unknown; /** * Выдает true, если атрубут с заданным наименованием существует, и false - если не существует. * @param key - Наименование атрибута объекта. * @see {@link GetOptProperty} * @see {@link GetOptProperty} * @see {@link SetProperty}. */ HasProperty(key: string | number): boolean; /** * Добавляет в объект новый атрибут, и присваивает ему значение. * @param {string} key - Наименование атрибута. * @param name - Значение атрибута. */ AddProperty(key: string | number, name: unknown): void; /** * Возвращает значение атрибута объекта. Если атрубут отсутствует, выдает undefined. * @param {string} key - Наименование атрибута объекта. * @param {unknown} [defaultValue] - Значение по умолчанию, возращаемое в случае отсутствия атрибута. */ GetOptProperty<O, K extends string, D = undefined>( this: O, key: K, defaultValue?: D ): K extends keyof O ? O[K] : D; /** * Выдает значение атрибута объекта. Если атрибут отсутствует, выдает ошибку. * @param {string} key - Наименование атрибута объекта. * @example AppConfig.GetProperty("alt-app-name"); * @throws {Error} * @see {@link GetOptProperty} * @see {@link SetProperty} */ GetProperty<O, K extends string>( this: O, key: K ): K extends keyof O ? O[K] : never; /** * Устанавливает значение атрибута объекта. * Если атрубут отсутствует, добавляет его. * @param key - Наименование атрибута объекта. * @param value - Значение атрибута объекта. * @see {@link GetOptProperty} * @see {@link SetProperty} */ SetProperty<T>(key: string | number, value: T): void; } interface ObjectConstructor { new(value?: unknown): Object; (value?: unknown): Object; (): Object; } declare const Object: ObjectConstructor; // Переопределение стандартного интерфейса Object для поддержки BorisType interface ObjectConstructor { /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param source The source object from which to copy properties. */ assign<T extends {}, U>(target: T, source: U): T & U; /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param source1 The first source object from which to copy properties. * @param source2 The second source object from which to copy properties. */ assign<T extends {}, U, V>(target: T, source1: U, source2: V): T & U & V; /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param source1 The first source object from which to copy properties. * @param source2 The second source object from which to copy properties. * @param source3 The third source object from which to copy properties. */ assign<T extends {}, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; /** * Copy the values of all of the enumerable own properties from one or more source objects to a * target object. Returns the target object. * @param target The target object to copy to. * @param sources One or more source objects from which to copy properties */ assign(target: object, ...sources: any[]): any; /** * Adds one or more properties to an object, and/or modifies attributes of existing properties. * @param o Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object. * @param properties JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property. */ defineProperties<T>(o: T, properties: PropertyDescriptorMap & ThisType<any>): T; /** * Adds a property to an object, or modifies attributes of an existing property. * @param o Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object. * @param p The property name. * @param attributes Descriptor for the property. It can be for a data property or an accessor property. */ defineProperty<T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>): T; /** * Returns an array of key/values of the enumerable own properties of an object * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ entries<T>(o: { [s: string]: T; } | ArrayLike<T>): [string, T][]; /** * Returns an array of key/values of the enumerable own properties of an object * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ entries(o: {}): [string, any][]; /** * Returns an object created by key-value entries for properties and methods * @param entries An iterable object that contains key-value entries for properties and methods. */ fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): { [k: string]: T; }; /** * Returns an object created by key-value entries for properties and methods * @param entries An iterable object that contains key-value entries for properties and methods. */ fromEntries(entries: Iterable<readonly any[]>): any; /** * Groups members of an iterable according to the return value of the passed callback. * @param items An iterable. * @param keySelector A callback which will be invoked for each item in items. */ groupBy<K extends PropertyKey, T>( items: Iterable<T>, keySelector: (item: T, index: number) => K, ): Partial<Record<K, T[]>>; /** * Returns the names of the enumerable string properties and methods of an object. * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ keys(o: {}): string[]; /** * Returns an array of values of the enumerable own properties of an object * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ values<T>(o: { [s: string]: T; } | ArrayLike<T>): T[]; /** * Returns an array of values of the enumerable own properties of an object * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ values(o: {}): any[]; } declare type PropertyKey = string | number | symbol; interface PropertyDescriptor { configurable?: boolean; enumerable?: boolean; value?: any; writable?: boolean; get?(): any; set?(v: any): void; } interface PropertyDescriptorMap { [key: PropertyKey]: PropertyDescriptor; } /** * Marker for contextual 'this' type */ interface ThisType<T> {}