TypeTools Interface
Table of Contents
Overview
The TypeToolsBase bas class serves as a utility for managing type extensions, validation, and manipulation within a TypeScript project. It facilitates:
- Type checking and validation
- Extension management for types
- Proxy-based handling for dynamic collections like lists and dictionaries
- Serialization and deserialization of data addresses
Classes & Interfaces
Type Extensions
The TypeToolsExtension interface provides a structure for defining extensions that can add, retrieve, and check data on various types.
export interface TypeToolsExtension {
getExtensionData: (target: any) => TypeToolsExtensionData;
implementOn: (target: any) => void;
typeCheck: (target: any) => boolean;
settings: TypeToolsSettings;
}
TypeToolsBase
- Purpose: Acts as the core utility class for type handling and extensions.
- Features:
- Extension Management: Add, get, and check extensions for types.
- Type Checking: Ensure objects conform to expected type specifications.
- Skeleton and Sample Instances: Generate template or example instances of types.
export class TypeToolsBase {
static topError: Error;
static topCancel: Error;
// ... more static properties and methods
settings: TypeToolsSettings;
constructor(settings?: Partial<TypeToolsSettings>) {
this.settings = settings ? Object.assign(new TypeToolsSettings(), settings) : TypeToolsSettings;
}
addExtension(target: any, extension: any) { /* implementation */ }
getExtension(target: any) { /* implementation */ }
init(target: any) { /* implementation */ }
}
Model Definition Helpers
ModelList
- Purpose: Provides a convenient way to create typed lists.
- Usage:
ModelList(type, init, parent, prop, order)
export function ModelList<T>(type?: Class<T>, init?: Array<T>, parent?: any, prop?: string, order: number = 1) {
if (!init) init = [];
return new List(init, parent, prop, type, order);
}
ModelDict
- Purpose: Provides a convenient way to create typed dictionaries.
- Usage:
ModelDict(init, parent, prop, rubric)
export function ModelDict<T>(init?: T, parent?: any, prop?: string, rubric?: { [propName: string]: Class<any> }) {
return new Dict(init, parent, prop, rubric) as T;
}
Proxy Handlers
The file utilizes Proxy Handlers to ensure type safety in dynamic data structures like List and Dict. These handlers manage set and get operations to enforce type conformity and handle validation errors gracefully.
Utility Functions
- isUndef: Checks if a variable is undefined or null.
- isFunction: Determines if a variable is a function.
- isArray: Determines if a variable is an array.
- isObject: Determines if a variable is an object.
- isModelInstance: Checks if an object is a type-checked model instance.
- isModelCollection: Checks if an object is a type-checked model collection.