@faast/ts-common
Advanced tools
Comparing version 0.2.4 to 0.2.5
@@ -5,2 +5,4 @@ import { ValidationError, Type } from 'io-ts'; | ||
export declare const SimpleReporter: Reporter<Array<string>>; | ||
export declare function assertType<T>(typeCodec: Type<T>, value: unknown, description?: string): T; | ||
export declare function assertType<T>(typeCodec: Type<T>, value: unknown, description?: string, ErrorType?: { | ||
new (message: string): Error; | ||
}): T; |
@@ -23,6 +23,6 @@ import { UnionType, IntersectionType } from 'io-ts'; | ||
}; | ||
export function assertType(typeCodec, value, description = 'type') { | ||
export function assertType(typeCodec, value, description = 'type', ErrorType = TypeError) { | ||
const validation = typeCodec.decode(value); | ||
if (validation.isLeft()) { | ||
throw new TypeError(`Invalid ${description} - ${SimpleReporter.report(validation)[0]}`); | ||
throw new ErrorType(`Invalid ${description} - ${SimpleReporter.report(validation)[0]}`); | ||
} | ||
@@ -29,0 +29,0 @@ return validation.value; |
{ | ||
"name": "@faast/ts-common", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "Common typescript types and utils used by faast", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -35,8 +35,13 @@ import { Context, ValidationError, UnionType, IntersectionType, Type } from 'io-ts' | ||
*/ | ||
export function assertType<T>(typeCodec: Type<T>, value: unknown, description: string = 'type'): T { | ||
export function assertType<T>( | ||
typeCodec: Type<T>, | ||
value: unknown, | ||
description: string = 'type', | ||
ErrorType: { new (message: string): Error } = TypeError, | ||
): T { | ||
const validation = typeCodec.decode(value) | ||
if (validation.isLeft()) { | ||
throw new TypeError(`Invalid ${description} - ${SimpleReporter.report(validation)[0]}`) | ||
throw new ErrorType(`Invalid ${description} - ${SimpleReporter.report(validation)[0]}`) | ||
} | ||
return validation.value | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
610325
7985