UNPKG

tg-map-vue3

Version:

封装 百度地图, Google地图, Here地图(未完成) 的Vue3组件库

91 lines (90 loc) 4.83 kB
import type { Component, ComponentPublicInstance } from 'vue'; /** deep版的 `Partial` */ export type DeepPartial<T> = { [U in keyof T]?: T[U] extends object ? DeepPartial<T[U]> : T[U]; }; /** 表示一个函数 */ export type AnyFunction = (...args: any[]) => any; /** * 表示一个构造器 * {@link import('vue/types/options').Constructor} * */ export type Constructor<T = {}> = new (...args: any[]) => T; /** * 抽象构造器类型, 相比{@link Constructor}, 不能直接用new创建对象 * @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures */ export type AbstractConstructor<T = {}> = abstract new (...args: any[]) => T; /** 原始类型=>包装类型 */ export type PrimitiveToWrapper<T> = T extends boolean ? boolean : T extends string ? string : T extends number ? number : T; /** 包装类型=>原始类型 */ export type WrapperToPrimitive<T> = T extends boolean ? boolean : T extends string ? string : T extends number ? number : T; /** * `vue instanceof VueConstructor`时`vue`并不会自动转换成`VueConstructor`的子类, 用该方法可以实现这种转换 */ export declare function isInstanceOf<T>(obj: any, constructor: Constructor<T>): obj is T; /** @see isInstanceOf */ export declare function safeAs<T>(obj: any, constructor: Constructor<T>): T | undefined; /** 判断{@link instance}是否是{@link component}的实例 */ export declare function isComponentByType<C extends Component & AbstractConstructor>(instance: ComponentPublicInstance | null, component: C): instance is InstanceType<C>; /** 安全转换组件类型, 若不能转换会返回`undefined` */ export declare function safeAsComponent<C extends Component & AbstractConstructor>(instance: ComponentPublicInstance | null, component: C): InstanceType<C> | undefined; /** * 查找[startInstance, endComponent)之间的第一个类型为{@link component}的父组件 * @param component 查找的组件 * @param startInstance 查找的开始实例, 包含 * @param endComponent 查找的终止组件, 不包含 * @returns */ export declare function findAncestorComponentByType<C extends Component & AbstractConstructor>(component: C, startInstance: ComponentPublicInstance | null, endComponent?: Component & AbstractConstructor): InstanceType<C> | undefined; /** {@link NonNullable} 的反义词 */ export type Nullable<T> = T | null | undefined; /** T的所有value的联合类型 */ export type ValueOf<T> = T[keyof T]; /** * 提取出T中value为V的子类的所有key * @see https://stackoverflow.com/questions/54520676/in-typescript-how-to-specify-only-keys-of-a-generic-object-whose-values-are-stri * */ export type KeysMatching<T, V> = { [K in keyof T]: T[K] extends V ? K : never; }[keyof T]; /** * 并不存在可以精确表示一个枚举类型, 该类只能近似表示一个字符枚举 * */ export type StringEnumLike = { [k: string]: string; }; /** * String枚举的值, 包括`string`类型 * @see https://stackoverflow.com/questions/52393730/typescript-string-literal-union-type-from-enum */ export type StringEnumValue<E extends StringEnumLike> = ValueOf<E> | `${ValueOf<E>}`; /** * 包装`T`中的部分枚举字段的值为{@link StringEnumValue} * * 会校验{@link EnumObjects}中的类型是否书写正确, 若写错, 会推断成`never` * */ export type WrapStringEnumValue<T, EnumObjects extends { [k in keyof T]?: StringEnumLike; }> = { [P in keyof T]: P extends keyof EnumObjects ? EnumObjects[P] extends StringEnumLike ? T[P] extends ValueOf<EnumObjects[P]> | undefined ? StringEnumValue<EnumObjects[P]> : never : never : T[P]; }; /** 取消包装`T`中的{@link StringEnumValue}字段 */ export declare function unwrapStringEnumValue<T extends object>(value: T): { [K in keyof T]: T[K] extends StringEnumValue<infer Enum> ? StringEnumLike extends Enum ? T[K] : Enum[keyof Enum] : Exclude<T[K], undefined> extends StringEnumValue<infer Enum> ? StringEnumLike extends Enum ? T[K] : Enum[keyof Enum] | undefined : T[K]; }; export declare function unwrapStringEnumValue<E extends StringEnumLike>(value: StringEnumValue<E>, enumObject?: E): E[keyof E]; export declare function unwrapStringEnumValue<E extends StringEnumLike>(value: StringEnumValue<E> | undefined, enumObject?: E): E[keyof E] | undefined; /** * 非空的值 * * 类型`{}`也表示"任何非空的值", 但由于它看起来像空对象, 所以一般更推荐用Thing * * @see https://github.com/microsoft/TypeScript/issues/7648#issuecomment-541625573 * @see https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492 */ export type Thing = string | number | boolean | bigint | object | symbol; /** 除T指定的类型外, 其他参数 */ export type TypedAny<T> = T & { [k: string]: any; };