UNPKG

@itrocks/property-type

Version:

Runtime type reflection from TypeScript declaration files for properties

58 lines (57 loc) 2.21 kB
import { KeyOf } from '@itrocks/class-type'; import { Type } from '@itrocks/class-type'; type LiteralValue = boolean | number | null | string | undefined; export type Canonical = BigInt | Boolean | Number | Object | String | Symbol | undefined; export declare class PropertyType { type: Canonical; optional: boolean; constructor(type: Canonical, optional?: boolean); get lead(): Canonical; } export declare class CanonicalType extends PropertyType { constructor(type: Canonical); } export declare class CollectionType extends PropertyType { elementType: PropertyType; constructor(type: Type, elementType: PropertyType); } export declare class CompositeType extends PropertyType { types: PropertyType[]; constructor(types: PropertyType[]); get lead(): Canonical; } type DeferredModule = Record<string, Type | undefined>; export declare class DeferredType<T extends DeferredModule = DeferredModule> { module: T; exportedName: KeyOf<T>; constructor(module: T, exportedName: KeyOf<T>); resolve(): T[KeyOf<T>]; } export declare class RecordType extends PropertyType { keyType: PropertyType; elementType: PropertyType; constructor(keyType: PropertyType, elementType: PropertyType); } export declare class IntersectionType extends CompositeType { } export declare class LiteralType extends PropertyType { value: LiteralValue; constructor(value: LiteralValue); } export declare class TypeType extends PropertyType { args?: PropertyType[] | undefined; constructor(type: DeferredType | Type, args?: PropertyType[] | undefined); get lead(): Canonical; } export declare class UnionType extends CompositeType { } export declare class UnknownType extends PropertyType { raw: string; constructor(raw: string); } export type PropertyTypes = Record<string, PropertyType>; export declare function isCanonical(propertyType: PropertyType, type?: Canonical): boolean; export declare function isLiteral(propertyType: PropertyType, literal?: LiteralValue): boolean; export declare function isType(propertyType: PropertyType, type?: Type): boolean; export declare function propertyTypesFromFile(file: string): PropertyTypes; export {};