Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/owl-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ function booleanType(): boolean {
} as any;
}

function numberType(): number {
function numberType<T extends number = number>(): T {
return function validateNumber(context: ValidationContext) {
if (typeof context.value !== "number") {
context.addIssue({ message: "value is not a number" });
}
} as any;
}

function stringType(): string {
function stringType<T extends string = string>(): T {
return function validateString(context: ValidationContext) {
if (typeof context.value !== "string" && !(context.value instanceof String)) {
context.addIssue({ message: "value is not a string" });
Expand All @@ -56,6 +56,7 @@ function stringType(): string {
}

function arrayType(): any[];
function arrayType<T>(): T[];
function arrayType<T>(elementType: T): T[];
function arrayType(elementType?: any): any {
return function validateArray(context: ValidationContext) {
Expand Down Expand Up @@ -103,6 +104,7 @@ function customValidator<T>(

function functionType(): (...parameters: any[]) => any;
function functionType<const P extends any[]>(parameters: P): (...parameters: P) => void;
function functionType<const P extends any[], R>(): (...parameters: P) => R;
function functionType<const P extends any[], R>(parameters: P, result: R): (...parameters: P) => R;
function functionType(parameters = [], result = undefined): (...parameters: any[]) => any {
return function validateFunction(context: ValidationContext) {
Expand Down Expand Up @@ -207,6 +209,7 @@ function objectType(): Record<string, any>;
function objectType<const Keys extends string[]>(
keys: Keys
): ResolveOptionalEntries<KeyedObject<Keys>>;
function objectType<Shape extends {}>(): ResolveOptionalEntries<Shape>;
function objectType<Shape extends {}>(shape: Shape): ResolveOptionalEntries<Shape>;
function objectType(schema = {}): Record<string, any> {
return function validateLooseObject(context: ValidationContext) {
Expand Down Expand Up @@ -292,6 +295,7 @@ function union<T extends any[]>(types: T): T[number] {
}

function reactiveValueType(): ReactiveValue<any>;
function reactiveValueType<T>(): ReactiveValue<T>;
function reactiveValueType<T>(type: T): ReactiveValue<T>;
function reactiveValueType(type?: any): ReactiveValue<any> {
return function validateReactiveValue(context: ValidationContext) {
Expand Down
Loading