superstruct
Advanced tools
Comparing version 0.10.11 to 0.10.12
@@ -284,2 +284,38 @@ /** | ||
declare function number(): Struct<number>; /** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
/** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
type Flatten<T> = T extends infer U ? { | ||
[K in keyof U]: U[K]; | ||
} : never; /** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
/** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
type OptionalKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? K : never; | ||
}[keyof T]; /** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
/** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
type RequiredKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? never : K; | ||
}[keyof T]; /** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
/** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
type OptionalizeObject<T> = Flatten<{ | ||
[K in RequiredKeys<T>]: T[K]; | ||
} & { | ||
[K in OptionalKeys<T>]?: T[K]; | ||
}>; /** | ||
* Validate that an object with specific entry values. | ||
@@ -291,5 +327,5 @@ */ | ||
declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>; | ||
declare function object<V extends StructRecord<any>>(Structs: V): Struct<{ | ||
declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{ | ||
[K in keyof V]: StructType<V[K]>; | ||
}, V>; | ||
}>, V>; | ||
/** | ||
@@ -296,0 +332,0 @@ * Augment a struct to make it optionally accept `undefined` values. |
@@ -284,2 +284,38 @@ /** | ||
declare function number(): Struct<number>; /** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
/** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
type Flatten<T> = T extends infer U ? { | ||
[K in keyof U]: U[K]; | ||
} : never; /** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
/** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
type OptionalKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? K : never; | ||
}[keyof T]; /** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
/** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
type RequiredKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? never : K; | ||
}[keyof T]; /** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
/** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
type OptionalizeObject<T> = Flatten<{ | ||
[K in RequiredKeys<T>]: T[K]; | ||
} & { | ||
[K in OptionalKeys<T>]?: T[K]; | ||
}>; /** | ||
* Validate that an object with specific entry values. | ||
@@ -291,5 +327,5 @@ */ | ||
declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>; | ||
declare function object<V extends StructRecord<any>>(Structs: V): Struct<{ | ||
declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{ | ||
[K in keyof V]: StructType<V[K]>; | ||
}, V>; | ||
}>, V>; | ||
/** | ||
@@ -296,0 +332,0 @@ * Augment a struct to make it optionally accept `undefined` values. |
@@ -92,8 +92,35 @@ import { Struct, StructType, StructContext } from './struct'; | ||
/** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
declare type Flatten<T> = T extends infer U ? { | ||
[K in keyof U]: U[K]; | ||
} : never; | ||
/** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
declare type OptionalKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? K : never; | ||
}[keyof T]; | ||
/** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
declare type RequiredKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? never : K; | ||
}[keyof T]; | ||
/** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
declare type OptionalizeObject<T> = Flatten<{ | ||
[K in RequiredKeys<T>]: T[K]; | ||
} & { | ||
[K in OptionalKeys<T>]?: T[K]; | ||
}>; | ||
/** | ||
* Validate that an object with specific entry values. | ||
*/ | ||
export declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>; | ||
export declare function object<V extends StructRecord<any>>(Structs: V): Struct<{ | ||
export declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{ | ||
[K in keyof V]: StructType<V[K]>; | ||
}, V>; | ||
}>, V>; | ||
/** | ||
@@ -173,2 +200,3 @@ * Augment a struct to make it optionally accept `undefined` values. | ||
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: StructTuple<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q>; | ||
export {}; | ||
//# sourceMappingURL=types.d.ts.map |
@@ -5,3 +5,3 @@ { | ||
"description": "A simple, expressive way to validate data in JavaScript.", | ||
"version": "0.10.11", | ||
"version": "0.10.12", | ||
"license": "MIT", | ||
@@ -41,3 +41,3 @@ "repository": "git://github.com/ianstormtaylor/superstruct.git", | ||
"lodash": "^4.17.15", | ||
"mocha": "^7.2.0", | ||
"mocha": "^8.0.1", | ||
"prettier": "^2.0.5", | ||
@@ -71,3 +71,4 @@ "rollup": "^2.12.0", | ||
"test:types": "tsc --noEmit && tsc --project ./test/tsconfig.json --noEmit", | ||
"watch": "yarn build:cjs --watch" | ||
"watch": "yarn build:cjs --watch", | ||
"watch:types": "yarn build:types --watch" | ||
}, | ||
@@ -74,0 +75,0 @@ "keywords": [ |
@@ -50,3 +50,3 @@ <p align="center"> | ||
```js | ||
import { assert, object, number, string, boolean, array } from 'superstruct' | ||
import { assert, object, number, string, array } from 'superstruct' | ||
@@ -106,3 +106,3 @@ const Article = object({ | ||
```ts | ||
import { assert, coerce, object, number, string, defaulted } from 'superstruct' | ||
import { coerce, object, number, string, defaulted } from 'superstruct' | ||
@@ -109,0 +109,0 @@ const User = object({ |
@@ -284,2 +284,38 @@ /** | ||
declare function number(): Struct<number>; /** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
/** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
type Flatten<T> = T extends infer U ? { | ||
[K in keyof U]: U[K]; | ||
} : never; /** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
/** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
type OptionalKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? K : never; | ||
}[keyof T]; /** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
/** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
type RequiredKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? never : K; | ||
}[keyof T]; /** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
/** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
type OptionalizeObject<T> = Flatten<{ | ||
[K in RequiredKeys<T>]: T[K]; | ||
} & { | ||
[K in OptionalKeys<T>]?: T[K]; | ||
}>; /** | ||
* Validate that an object with specific entry values. | ||
@@ -291,5 +327,5 @@ */ | ||
declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>; | ||
declare function object<V extends StructRecord<any>>(Structs: V): Struct<{ | ||
declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{ | ||
[K in keyof V]: StructType<V[K]>; | ||
}, V>; | ||
}>, V>; | ||
/** | ||
@@ -296,0 +332,0 @@ * Augment a struct to make it optionally accept `undefined` values. |
@@ -284,2 +284,38 @@ /** | ||
declare function number(): Struct<number>; /** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
/** | ||
* Type helper to Flatten the Union of optional and required properties. | ||
*/ | ||
type Flatten<T> = T extends infer U ? { | ||
[K in keyof U]: U[K]; | ||
} : never; /** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
/** | ||
* Type helper to extract the optional keys of an object | ||
*/ | ||
type OptionalKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? K : never; | ||
}[keyof T]; /** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
/** | ||
* Type helper to extract the required keys of an object | ||
*/ | ||
type RequiredKeys<T> = { | ||
[K in keyof T]: undefined extends T[K] ? never : K; | ||
}[keyof T]; /** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
/** | ||
* Type helper to create optional properties when the property value can be | ||
* undefined (ie. when `optional()` is used to define a type) | ||
*/ | ||
type OptionalizeObject<T> = Flatten<{ | ||
[K in RequiredKeys<T>]: T[K]; | ||
} & { | ||
[K in OptionalKeys<T>]?: T[K]; | ||
}>; /** | ||
* Validate that an object with specific entry values. | ||
@@ -291,5 +327,5 @@ */ | ||
declare function object<V extends StructRecord<any>>(): Struct<Record<string, unknown>>; | ||
declare function object<V extends StructRecord<any>>(Structs: V): Struct<{ | ||
declare function object<V extends StructRecord<any>>(Structs: V): Struct<OptionalizeObject<{ | ||
[K in keyof V]: StructType<V[K]>; | ||
}, V>; | ||
}>, V>; | ||
/** | ||
@@ -296,0 +332,0 @@ * Augment a struct to make it optionally accept `undefined` values. |
Sorry, the diff of this file is not supported yet
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
384338
48
4842