Socket
Socket
Sign inDemoInstall

@sinclair/typebox

Package Overview
Dependencies
0
Maintainers
1
Versions
310
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.9.1 to 0.9.2

license

2

package.json
{
"name": "@sinclair/typebox",
"version": "0.9.1",
"version": "0.9.2",
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",

@@ -5,0 +5,0 @@ "author": "sinclairzx81",

@@ -12,3 +12,2 @@ <div align='center'>

</div>

@@ -20,5 +19,5 @@

```bash
$ npm install @sinclair/typebox --save
```
npm install @sinclair/typebox --save
```

@@ -29,8 +28,6 @@ <a name="Overview"></a>

TypeBox is a type builder library that allows developers to compose complex in-memory JSONSchema objects that can be resolved to static TypeScript types. TypeBox internally represents its types as plain JSONSchema objects and leverages TypeScript's [Mapped Types](https://www.typescriptlang.org/docs/handbook/advanced-types.html#mapped-types) to infer schemas to equivalent static type representations. No additional build process is required.
TypeBox is a type builder library that allows developers to compose complex in-memory JSONSchema objects that can be resolved to static TypeScript types. The schemas produced by TypeBox can be used directly as validation schemas or reflected upon by navigating the standard JSONSchema properties at runtime. TypeBox can be used as a simple tool to build complex schemas or integrated into RPC or REST services to help validate JSON data received over the wire.
TypeBox can be used as a tool to build and validate complex schemas, or integrated into RPC or REST services to help validate data received over the wire or published directly to consumers to service as developer documentation.
TypeBox does not provide any mechanism for validating JSONSchema. Please refer to libraries such as [AJV](https://www.npmjs.com/package/ajv) or similar to validate the schemas created with this library.
Note that TypeBox does not provide any mechanisms for validating JSONSchema. Please refer to libraries such as [AJV](https://www.npmjs.com/package/ajv) or similar to validate the schemas created with this library.
Requires TypeScript 3.8.3 and above.

@@ -45,4 +42,5 @@

- [Types](#Types)
- [Other Types](#Intrinsics)
- [More Types](#Intrinsics)
- [Functions](#Functions)
- [Generics](#Generics)
- [Validation](#Validation)

@@ -52,3 +50,3 @@

The following shows the type alias for `Order` and its TypeBox equivalent.
The following shows the general usage.

@@ -104,8 +102,6 @@ ```typescript

TypeBox functions generate JSONschema objects. The following table outlines the TypeScript and JSONSchema equivalence.
TypeBox provides many functions generate JSONschema data types. The following tables list the functions TypeBox provides and their respective TypeScript and JSONSchema equivalents.
### TypeBox > TypeScript
The following types and modifiers are compatible with JSONschema and have both JSONschema and TypeScript representations.
<table>

@@ -215,4 +211,2 @@ <thead>

The following shows the TypeBox to JSONSchema mappings. The following schemas are returned from each function.
<table>

@@ -274,3 +268,3 @@ <thead>

<td>Tuple</td>
<td><code>const T = Type.Union(Type.Number(), Type.String())</code></td>
<td><code>const T = Type.Tuple(Type.Number(), Type.String())</code></td>
<td><code>{ type: "array", items: [{type: 'string'}, {type: 'number'}], additionalItems: false, minItems: 2, maxItems: 2 }</code></td>

@@ -314,9 +308,9 @@ </tr>

## Other Types
## More Types
TypeBox provides some non-standard JSONSchema functions that TypeBox refers to as Intrinsic types. While these types cannot be used with JSONSchema, they do provide similar reflection and introspection metadata for expressing function signatures with TypeBox.
In addition to the JSONSchema functions, TypeBox also provides some non-standard schemas that provide reflectable metadata for function signatures. These functions allow TypeBox to express `function` and `constructor` signatures where the arguments and return types may be JSONSchema.
See [Functions](#Functions) section for more details.
For more information on their use, see the [Functions](#Functions) and [Generics](#Generics) sections below.
### TypeBox > Intrinsics
### TypeBox > TypeScript

@@ -336,4 +330,9 @@ <table>

<td><code>type T = (arg0: string) => string</code></td>
</tr>
</tr>
<tr>
<td>Constructor</td>
<td><code>const T = Type.Constructor([Type.String()], Type.String())</code></td>
<td><code>type T = new (arg0: string) => string</code></td>
</tr>
<tr>
<td>Promise</td>

@@ -356,3 +355,3 @@ <td><code>const T = Type.Promise(Type.String())</code></td>

### TypeBox > Non Schema
### TypeBox > TypeBox Schema

@@ -364,3 +363,3 @@ <table>

<th>TypeBox</th>
<th>TypeScript</th>
<th>Metadata</th>
</tr>

@@ -373,4 +372,9 @@ </thead>

<td><code>{ type: 'function', arguments: [ { type: 'string' } ], returns: { type: 'number' } }</code></td>
</tr>
</tr>
<tr>
<td>Constructor</td>
<td><code>const T = Type.Constructor([Type.String()], Type.Number())</code></td>
<td><code>{ type: 'constructor', arguments: [ { type: 'string' } ], returns: { type: 'number' } }</code></td>
</tr>
<tr>
<td>Promise</td>

@@ -397,10 +401,9 @@ <td><code>const T = Type.Promise(Type.String())</code></td>

TypeBox provides some capabilities for building typed function signatures. It is important to note however that unlike the other functions available on `Type` the `Type.Function(...)` and other intrinsic types do not produce valid JSONSchema. However, the types returned from `Type.Function(...)` may be comprised of schemas that describe its `arguments` and `return` types. Consider the following TypeScript and TypeBox variants.
The following demonstrates creating function signatures for the following TypeScript types.
### TypeScript
```typescript
type T0 = (a0: number, a1: string) => boolean;
// TypeScript
type T0 = (a0: number, a0: number) => number;
type T1 = (a0: string, a1: () => string) => void;

@@ -412,10 +415,10 @@

// Convention
type T4 = new () => string
```
Type.Function([...Arguments], ReturnType)
### TypeBox
// TypeBox
```typescript
const T0 = Type.Function([Type.Number(), Type.String()], Type.Boolean())
const T0 = Type.Function([Type.Number(), Type.Number()], Type.Number())
const T1 = Type.Function([Type.String(), Type.Function([], Type.String())], Type.Void())

@@ -426,66 +429,98 @@

const T3 = Type.Function([], Type.Function([], Type.String()))
const T4 = Type.Constructor([], Type.String())
```
<a href='Validation'></a>
<a name="Generics"></a>
## Validation
## Generics
TypeBox does not provide any mechanism for validating JSONSchema out of the box. Users are expected to bring their own JSONSchema validation library. The following demonstrates how you might enable validation with the AJV npm module.
Generic function signatures can be composed with TypeScript functions with [Generic Constraints](https://www.typescriptlang.org/docs/handbook/generics.html#generic-constraints).
### General
### TypeScript
```typescript
type ToString = <T>(t: T) => string
```
### TypeBox
```typescript
import { Type, Static, TStatic } from '@sinclair/typebox'
const ToString = <G extends TStatic>(T: G) => Type.Function([T], Type.String())
```
However, it's not possible to statically infer what type `ToString` is without first creating some specialized variant of it. The following creates a specialization called `NumberToString`.
```typescript
import * Ajv from 'ajv'
const NumberToString = ToString(Type.Number())
const ajv = new Ajv({ })
type X = Static<typeof NumberToString>
ajv.validate(Type.String(), 'hello') // true
// X is (arg0: number) => string
```
To take things a bit further, the following code contains some generic TypeScript REST setup with controllers that take some generic resource of type `T`. Below this we expresses that same setup using TypeBox. The resulting type `IRecordController` contains reflectable metadata about the `RecordController`.
### TypeScript
```typescript
interface IController<T> {
get (): Promise<T>
post (resource: T): Promise<void>
put (resource: T): Promise<void>
delete (resource: T): Promise<void>
}
ajv.validate(Type.String(), 123) // false
interface Record {
key: string
value: string
}
class StringController implements IController<Record> {
async get (): Promise<Record> { throw 'not implemented' }
async post (resource: Record): Promise<void> { /* */ }
async put (resource: Record): Promise<void> { /* */ }
async delete(resource: Record): Promise<void> { /* */ }
}
```
### Runtime Type Validation
### TypeBox
The following demonstrates how you might want to approach runtime type validation with TypeBox. The following
code creates a function that takes a signature type `S` which is used to infer function arguments. The body
of the function validates with the signatures `arguments` and `returns` schemas against values passed by the
caller.
```typescript
import { Type, Static, TFunction } from '@sinclair/typebox'
import { Type, Static, TStatic } from '@sinclair/typebox'
// Some validation function.
declare function validate(schema: any, data: any): boolean;
const IController = <G extends TStatic>(T: G) => Type.Object({
get: Type.Function([], Type.Promise(T)),
post: Type.Function([T], Type.Promise(Type.Void())),
put: Type.Function([T], Type.Promise(Type.Void())),
delete: Type.Function([T], Type.Promise(Type.Void())),
})
// A function that returns a closure that validates its
// arguments and return value from the given signature.
function Func<S extends TFunction>(signature: S, func: Static<S>): Static<S> {
const validator = (...params: any[]) => {
params.forEach((param, index) => {
if(!validate(signature.arguments[index], param)) {
console.log('error on argument', index)
}
})
const result = (func as Function)(...params);
if(!validate(signature.return, result)) {
console.log('error on return')
}
return result
}
return validator as Static<S>
type Record = Static<typeof Record>
const Record = Type.Object({
key: Type.String(),
value: Type.String()
})
type IRecordController = Static<typeof IRecordController>
const IRecordController = IController(Record)
class RecordController implements IRecordController {
async get (): Promise<Record> { throw 'not implemented' }
async post (resource: Record): Promise<void> { /* */ }
async put (resource: Record): Promise<void> { /* */ }
async delete(resource: Record): Promise<void> { /* */ }
}
// Create some function.
const Add = Func(
Type.Function([
Type.Number(),
Type.Number()
], Type.Number()),
(a, b) => {
return a + b
})
// Reflect !!
console.log(IRecordController)
```
<a href='Validation'></a>
// Call it
Add(20, 30)
## Validation
```
The following uses the library [Ajv](https://www.npmjs.com/package/ajv) to validate a type.
```typescript
import * Ajv from 'ajv'
const ajv = new Ajv({ })
ajv.validate(Type.String(), 'hello') // true
ajv.validate(Type.String(), 123) // false
```
interface TFunction8<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, T4 extends TSchema, T5 extends TSchema, T6 extends TSchema, T7 extends TSchema, U extends TSchema> {
type: 'function';
arguments: [T0, T1, T2, T3, T4, T5, T6, T7];
return: U;
returns: U;
}

@@ -9,3 +9,3 @@ interface TFunction7<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, T4 extends TSchema, T5 extends TSchema, T6 extends TSchema, U extends TSchema> {

arguments: [T0, T1, T2, T3, T4, T5, T6];
return: U;
returns: U;
}

@@ -15,3 +15,3 @@ interface TFunction6<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, T4 extends TSchema, T5 extends TSchema, U extends TSchema> {

arguments: [T0, T1, T2, T3, T4, T5];
return: U;
returns: U;
}

@@ -21,3 +21,3 @@ interface TFunction5<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, T4 extends TSchema, U extends TSchema> {

arguments: [T0, T1, T2, T3, T4];
return: U;
returns: U;
}

@@ -27,3 +27,3 @@ interface TFunction4<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, U extends TSchema> {

arguments: [T0, T1, T2, T3];
return: U;
returns: U;
}

@@ -33,3 +33,3 @@ interface TFunction3<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, U extends TSchema> {

arguments: [T0, T1, T2];
return: U;
returns: U;
}

@@ -39,3 +39,3 @@ interface TFunction2<T0 extends TSchema, T1 extends TSchema, U extends TSchema> {

arguments: [T0, T1];
return: U;
returns: U;
}

@@ -45,3 +45,3 @@ interface TFunction1<T0 extends TSchema, U extends TSchema> {

arguments: [T0];
return: U;
returns: U;
}

@@ -54,3 +54,49 @@ interface TFunction0<U extends TSchema> {

export declare type TFunction = TFunction8<TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema> | TFunction7<TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema> | TFunction6<TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema> | TFunction5<TSchema, TSchema, TSchema, TSchema, TSchema, TSchema> | TFunction4<TSchema, TSchema, TSchema, TSchema, TSchema> | TFunction3<TSchema, TSchema, TSchema, TSchema> | TFunction2<TSchema, TSchema, TSchema> | TFunction1<TSchema, TSchema> | TFunction0<TSchema>;
export declare type TIntrinsic = TFunction | TVoid | TUndefined | TPromise<any>;
interface TConstructor8<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, T4 extends TSchema, T5 extends TSchema, T6 extends TSchema, T7 extends TSchema, U extends TSchema> {
type: 'constructor';
arguments: [T0, T1, T2, T3, T4, T5, T6, T7];
returns: U;
}
interface TConstructor7<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, T4 extends TSchema, T5 extends TSchema, T6 extends TSchema, U extends TSchema> {
type: 'constructor';
arguments: [T0, T1, T2, T3, T4, T5, T6];
returns: U;
}
interface TConstructor6<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, T4 extends TSchema, T5 extends TSchema, U extends TSchema> {
type: 'constructor';
arguments: [T0, T1, T2, T3, T4, T5];
returns: U;
}
interface TConstructor5<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, T4 extends TSchema, U extends TSchema> {
type: 'constructor';
arguments: [T0, T1, T2, T3, T4];
returns: U;
}
interface TConstructor4<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, T3 extends TSchema, U extends TSchema> {
type: 'constructor';
arguments: [T0, T1, T2, T3];
returns: U;
}
interface TConstructor3<T0 extends TSchema, T1 extends TSchema, T2 extends TSchema, U extends TSchema> {
type: 'constructor';
arguments: [T0, T1, T2];
returns: U;
}
interface TConstructor2<T0 extends TSchema, T1 extends TSchema, U extends TSchema> {
type: 'constructor';
arguments: [T0, T1];
returns: U;
}
interface TConstructor1<T0 extends TSchema, U extends TSchema> {
type: 'constructor';
arguments: [T0];
returns: U;
}
interface TConstructor0<U extends TSchema> {
type: 'constructor';
arguments: [];
returns: U;
}
export declare type TConstructor = TConstructor8<TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema> | TConstructor7<TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema> | TConstructor6<TSchema, TSchema, TSchema, TSchema, TSchema, TSchema, TSchema> | TConstructor5<TSchema, TSchema, TSchema, TSchema, TSchema, TSchema> | TConstructor4<TSchema, TSchema, TSchema, TSchema, TSchema> | TConstructor3<TSchema, TSchema, TSchema, TSchema> | TConstructor2<TSchema, TSchema, TSchema> | TConstructor1<TSchema, TSchema> | TConstructor0<TSchema>;
export declare type TIntrinsic = TFunction | TConstructor | TPromise<any> | TVoid | TUndefined;
export interface TPromise<T extends TSchema | TVoid | TUndefined> {

@@ -174,6 +220,6 @@ type: 'promise';

export declare type TComposite = TIntersect | TUnion | TTuple;
export declare type TOptional<T extends TSchema | TUnion | TIntersect | TTuple> = T & {
export declare type TOptional<T extends TSchema | TComposite> = T & {
modifier: 'optional';
};
export declare type TReadonly<T extends TSchema | TUnion | TIntersect | TTuple> = T & {
export declare type TReadonly<T extends TSchema | TComposite> = T & {
modifier: 'readonly';

@@ -197,3 +243,3 @@ };

export interface TProperties {
[key: string]: TSchema | TUnion | TIntersect | TTuple | TOptional<TSchema | TUnion | TIntersect | TTuple> | TReadonly<TSchema | TUnion | TIntersect | TTuple>;
[key: string]: TSchema | TComposite | TOptional<TSchema | TComposite> | TReadonly<TSchema | TComposite>;
}

@@ -205,7 +251,7 @@ export interface TObject<T extends TProperties> {

}
export interface TMap<T extends TSchema | TUnion | TIntersect | TTuple> {
export interface TMap<T extends TSchema | TComposite> {
type: 'object';
additionalProperties: T;
}
export interface TArray<T extends TSchema | TUnion | TIntersect | TTuple> {
export interface TArray<T extends TSchema | TComposite> {
type: 'array';

@@ -243,3 +289,4 @@ items: T;

declare type StaticFunction<T> = T extends TFunction8<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer U6, infer U7, infer R> ? (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>, arg4: Static<U4>, arg5: Static<U5>, arg6: Static<U6>, arg7: Static<U7>) => Static<R> : T extends TFunction7<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer U6, infer R> ? (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>, arg4: Static<U4>, arg5: Static<U5>, arg6: Static<U6>) => Static<R> : T extends TFunction6<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer R> ? (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>, arg4: Static<U4>, arg5: Static<U5>) => Static<R> : T extends TFunction5<infer U0, infer U1, infer U2, infer U3, infer U4, infer R> ? (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>, arg4: Static<U4>) => Static<R> : T extends TFunction4<infer U0, infer U1, infer U2, infer U3, infer R> ? (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>) => Static<R> : T extends TFunction3<infer U0, infer U1, infer U2, infer R> ? (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>) => Static<R> : T extends TFunction2<infer U0, infer U1, infer R> ? (arg0: Static<U0>, arg1: Static<U1>) => Static<R> : T extends TFunction1<infer U0, infer R> ? (arg0: Static<U0>) => Static<R> : T extends TFunction0<infer R> ? () => Static<R> : never;
declare type StaticInstrinsic<T extends TIntrinsic> = T extends TFunction ? StaticFunction<T> : T extends TPromise<infer U> ? Promise<Static<U>> : T extends TVoid ? void : T extends TUndefined ? undefined : never;
declare type StaticConstructor<T> = T extends TConstructor8<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer U6, infer U7, infer R> ? new (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>, arg4: Static<U4>, arg5: Static<U5>, arg6: Static<U6>, arg7: Static<U7>) => Static<R> : T extends TConstructor7<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer U6, infer R> ? new (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>, arg4: Static<U4>, arg5: Static<U5>, arg6: Static<U6>) => Static<R> : T extends TConstructor6<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer R> ? new (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>, arg4: Static<U4>, arg5: Static<U5>) => Static<R> : T extends TConstructor5<infer U0, infer U1, infer U2, infer U3, infer U4, infer R> ? new (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>, arg4: Static<U4>) => Static<R> : T extends TConstructor4<infer U0, infer U1, infer U2, infer U3, infer R> ? new (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>, arg3: Static<U3>) => Static<R> : T extends TConstructor3<infer U0, infer U1, infer U2, infer R> ? new (arg0: Static<U0>, arg1: Static<U1>, arg2: Static<U2>) => Static<R> : T extends TConstructor2<infer U0, infer U1, infer R> ? new (arg0: Static<U0>, arg1: Static<U1>) => Static<R> : T extends TConstructor1<infer U0, infer R> ? new (arg0: Static<U0>) => Static<R> : T extends TConstructor0<infer R> ? new () => Static<R> : never;
declare type StaticInstrinsic<T extends TIntrinsic> = T extends TFunction ? StaticFunction<T> : T extends TConstructor ? StaticConstructor<T> : T extends TPromise<infer U> ? Promise<Static<U>> : T extends TVoid ? void : T extends TUndefined ? undefined : never;
declare type StaticIntersect<T> = T extends TIntersect8<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer U6, infer U7> ? StaticSchema<U0> & StaticSchema<U1> & StaticSchema<U2> & StaticSchema<U3> & StaticSchema<U4> & StaticSchema<U5> & StaticSchema<U6> & StaticSchema<U7> : T extends TIntersect7<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer U6> ? StaticSchema<U0> & StaticSchema<U1> & StaticSchema<U2> & StaticSchema<U3> & StaticSchema<U4> & StaticSchema<U5> & StaticSchema<U6> : T extends TIntersect6<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5> ? StaticSchema<U0> & StaticSchema<U1> & StaticSchema<U2> & StaticSchema<U3> & StaticSchema<U4> & StaticSchema<U5> : T extends TIntersect5<infer U0, infer U1, infer U2, infer U3, infer U4> ? StaticSchema<U0> & StaticSchema<U1> & StaticSchema<U2> & StaticSchema<U3> & StaticSchema<U4> : T extends TIntersect4<infer U0, infer U1, infer U2, infer U3> ? StaticSchema<U0> & StaticSchema<U1> & StaticSchema<U2> & StaticSchema<U3> : T extends TIntersect3<infer U0, infer U1, infer U2> ? StaticSchema<U0> & StaticSchema<U1> & StaticSchema<U2> : T extends TIntersect2<infer U0, infer U1> ? StaticSchema<U1> & StaticSchema<U0> : T extends TIntersect1<infer U0> ? StaticSchema<U0> : never;

@@ -290,8 +337,2 @@ declare type StaticUnion<T> = T extends TUnion8<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer U6, infer U7> ? StaticSchema<U0> | StaticSchema<U1> | StaticSchema<U2> | StaticSchema<U3> | StaticSchema<U4> | StaticSchema<U5> | StaticSchema<U6> | StaticSchema<U7> : T extends TUnion7<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5, infer U6> ? StaticSchema<U0> | StaticSchema<U1> | StaticSchema<U2> | StaticSchema<U3> | StaticSchema<U4> | StaticSchema<U5> | StaticSchema<U6> : T extends TUnion6<infer U0, infer U1, infer U2, infer U3, infer U4, infer U5> ? StaticSchema<U0> | StaticSchema<U1> | StaticSchema<U2> | StaticSchema<U3> | StaticSchema<U4> | StaticSchema<U5> : T extends TUnion5<infer U0, infer U1, infer U2, infer U3, infer U4> ? StaticSchema<U0> | StaticSchema<U1> | StaticSchema<U2> | StaticSchema<U3> | StaticSchema<U4> : T extends TUnion4<infer U0, infer U1, infer U2, infer U3> ? StaticSchema<U0> | StaticSchema<U1> | StaticSchema<U2> | StaticSchema<U3> : T extends TUnion3<infer U0, infer U1, infer U2> ? StaticSchema<U0> | StaticSchema<U1> | StaticSchema<U2> : T extends TUnion2<infer U0, infer U1> ? StaticSchema<U0> | StaticSchema<U1> : T extends TUnion1<infer U0> ? StaticSchema<U0> : never;

static Any(): TAny;
/** Creates a Promise type. */
static Promise<T extends TSchema>(t: T): TPromise<T>;
/** Creates a Void type. */
static Void(): TVoid;
/** Creates a Undefined type. */
static Undefined(): TUndefined;
/** Creates a StringLiteral for the given value. */

@@ -369,2 +410,26 @@ static Literal<T extends string>(value: T): TStringLiteral<T>;

static Function<U extends TStatic>(args: [], returns: U): TFunction0<U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<T0 extends TStatic, T1 extends TStatic, T2 extends TStatic, T3 extends TStatic, T4 extends TStatic, T5 extends TStatic, T6 extends TStatic, T7 extends TStatic, U extends TStatic>(args: [T0, T1, T2, T3, T4, T5, T6, T7], returns: U): TConstructor8<T0, T1, T2, T3, T4, T5, T6, T7, U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<T0 extends TStatic, T1 extends TStatic, T2 extends TStatic, T3 extends TStatic, T4 extends TStatic, T5 extends TStatic, T6 extends TStatic, U extends TStatic>(args: [T0, T1, T2, T3, T4, T5, T6], returns: U): TConstructor7<T0, T1, T2, T3, T4, T5, T6, U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<T0 extends TStatic, T1 extends TStatic, T2 extends TStatic, T3 extends TStatic, T4 extends TStatic, T5 extends TStatic, U extends TStatic>(args: [T0, T1, T2, T3, T4, T5], returns: U): TConstructor6<T0, T1, T2, T3, T4, T5, U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<T0 extends TStatic, T1 extends TStatic, T2 extends TStatic, T3 extends TStatic, T4 extends TStatic, U extends TStatic>(args: [T0, T1, T2, T3, T4], returns: U): TConstructor5<T0, T1, T2, T3, T4, U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<T0 extends TStatic, T1 extends TStatic, T2 extends TStatic, T3 extends TStatic, U extends TStatic>(args: [T0, T1, T2, T3], returns: U): TConstructor4<T0, T1, T2, T3, U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<T0 extends TStatic, T1 extends TStatic, T2 extends TStatic, U extends TStatic>(args: [T0, T1, T2], returns: U): TConstructor3<T0, T1, T2, U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<T0 extends TStatic, T1 extends TStatic, U extends TStatic>(args: [T0, T1], returns: U): TConstructor2<T0, T1, U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<T0 extends TStatic, U extends TStatic>(args: [T0], returns: U): TConstructor1<T0, U>;
/** Creates a Constructor type for the given arguments. */
static Constructor<U extends TStatic>(args: [], returns: U): TConstructor0<U>;
/** Creates a Promise type. */
static Promise<T extends TSchema>(t: T): TPromise<T>;
/** Creates a Void type. */
static Void(): TVoid;
/** Creates a Undefined type. */
static Undefined(): TUndefined;
/** Creates a Pattern type that resolves to a string. */

@@ -371,0 +436,0 @@ static Pattern(regex: RegExp): TPattern;

@@ -89,16 +89,2 @@ "use strict";

}
// #endregion
// #region PrimitiveExtended
/** Creates a Promise type. */
static Promise(t) {
return { type: 'promise', item: t };
}
/** Creates a Void type. */
static Void() {
return { type: 'void' };
}
/** Creates a Undefined type. */
static Undefined() {
return { type: 'undefined' };
}
/** Creates a Literal for the given value. */

@@ -132,2 +118,18 @@ static Literal(value) {

}
/** Creates a Constructor type for the given arguments. */
static Constructor(args, returns) {
return { type: 'constructor', arguments: args, returns: returns };
}
/** Creates a Promise type. */
static Promise(t) {
return { type: 'promise', item: t };
}
/** Creates a Void type. */
static Void() {
return { type: 'void' };
}
/** Creates a Undefined type. */
static Undefined() {
return { type: 'undefined' };
}
// #endregion

@@ -134,0 +136,0 @@ // #region Extended

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc