Skip to content

Commit

Permalink
Revision 0.32.18 (#801)
Browse files Browse the repository at this point in the history
- Explicit Return on TypeSystem Type
  • Loading branch information
sinclairzx81 committed Mar 21, 2024
1 parent ec27004 commit 8a6018d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.32.17",
"version": "0.32.18",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand Down
6 changes: 4 additions & 2 deletions src/system/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

import { TypeRegistry, FormatRegistry } from '../type/registry/index'
import { Unsafe } from '../type/unsafe/index'
import { Unsafe, type TUnsafe } from '../type/unsafe/index'
import { Kind } from '../type/symbols/index'
import { TypeBoxError } from '../type/error/index'

Expand All @@ -47,10 +47,12 @@ export class TypeSystemDuplicateFormat extends TypeBoxError {
// ------------------------------------------------------------------
// TypeSystem
// ------------------------------------------------------------------
export type TypeFactoryFunction<Type, Options = Record<PropertyKey, unknown>> = (options?: Partial<Options>) => TUnsafe<Type>

/** Creates user defined types and formats and provides overrides for value checking behaviours */
export namespace TypeSystem {
/** Creates a new type */
export function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean) {
export function Type<Type, Options = Record<PropertyKey, unknown>>(kind: string, check: (options: Options, value: unknown) => boolean): TypeFactoryFunction<Type, Options> {
if (TypeRegistry.Has(kind)) throw new TypeSystemDuplicateTypeKind(kind)
TypeRegistry.Set(kind, check)
return (options: Partial<Options> = {}) => Unsafe<Type>({ ...options, [Kind]: kind })
Expand Down

0 comments on commit 8a6018d

Please sign in to comment.