Comparing version 0.0.0-dev.20201229022322 to 0.0.0-dev.20201229023359
@@ -23,20 +23,4 @@ declare namespace AsTypedInternal { | ||
type TypeName<T> = T extends null | ||
? "null" | ||
: T extends string | ||
? "string" | ||
: T extends any[] | ||
? "array" | ||
: T extends number | ||
? "number" | "integer" | ||
: T extends boolean | ||
? "boolean" | ||
: "object"; | ||
interface WithID { | ||
$id: string; | ||
} | ||
type SchemaDeclaration<Type> = SchemaBase & { | ||
type: TypeName<Type>; | ||
type: Type; | ||
$id?: string; | ||
@@ -57,3 +41,3 @@ }; | ||
type NumberSchema = SchemaDeclaration<number> & { | ||
type NumberSchema = SchemaDeclaration<"number" | "integer"> & { | ||
multipleOf?: number; | ||
@@ -66,3 +50,3 @@ minimun?: number; | ||
type StringSchema = SchemaDeclaration<string> & { | ||
type StringSchema = SchemaDeclaration<"string"> & { | ||
pattern?: RegExp; | ||
@@ -84,8 +68,4 @@ maxLength?: number; | ||
type BoolSchema = SchemaDeclaration<boolean>; | ||
type BoolSchema = SchemaDeclaration<"boolean">; | ||
type NullSchema = SchemaDeclaration<null>; | ||
type LeafSchema = NumberSchema | StringSchema | BoolSchema | NullSchema; | ||
type ObjectSchema< | ||
@@ -95,3 +75,3 @@ Props, | ||
AdditionalProps extends SchemaBase | null = null | ||
> = SchemaDeclaration<{}> & { | ||
> = SchemaDeclaration<"object"> & { | ||
required?: ReqProps; | ||
@@ -133,3 +113,3 @@ properties?: Props; | ||
type ArraySchemaBase = SchemaDeclaration<any[]> & { | ||
type ArraySchemaBase = SchemaDeclaration<"array"> & { | ||
maxItems?: number; | ||
@@ -210,4 +190,2 @@ minItems?: number; | ||
// This is very crude | ||
type ResolveNot<ValueType> = | ||
@@ -217,3 +195,3 @@ // TODO: allow Not() for array/object types of specific schemas. Not easy. | ||
| any[] | ||
| (ValueType extends NullSchema ? never : null) | ||
| (ValueType extends SchemaDeclaration<"null"> ? never : null) | ||
| (ValueType extends NumberSchema ? never : number) | ||
@@ -227,11 +205,11 @@ | (ValueType extends StringSchema ? never : string) | ||
? ResolveRecursiveInternal<Omit<SchemaType, "nullable">> | null | ||
: SchemaType extends SchemaDeclaration<null> | ||
: SchemaType extends SchemaDeclaration<"null"> | ||
? null | ||
: SchemaType extends ConstSchema<infer Value> | ||
? Value | ||
: SchemaType extends SchemaDeclaration<string> | ||
: SchemaType extends SchemaDeclaration<"string"> | ||
? string | ||
: SchemaType extends SchemaDeclaration<boolean> | ||
: SchemaType extends SchemaDeclaration<"boolean"> | ||
? boolean | ||
: SchemaType extends SchemaDeclaration<number> | ||
: SchemaType extends SchemaDeclaration<"number" | "integer"> | ||
? number | ||
@@ -316,3 +294,3 @@ : SchemaType extends TupleSchema<infer TupleType, infer Additional> | ||
Definitions extends DefinitionsBase | ||
> = SchemaDeclaration<any[]> & { | ||
> = SchemaDeclaration<"array"> & { | ||
items: ResolveRefs<RootSchema, ValueType, Definitions>; | ||
@@ -326,3 +304,3 @@ }; | ||
Definitions extends DefinitionsBase | ||
> = SchemaDeclaration<any[]> & { | ||
> = SchemaDeclaration<"array"> & { | ||
items: ResolveRefs<RootSchema, Tuple, Definitions>; | ||
@@ -412,10 +390,3 @@ additionalItems: ResolveRefs<RootSchema, Additional, Definitions>; | ||
type DeepUnReadonly<T> = T extends | ||
| string | ||
| number | ||
| boolean | ||
| undefined | ||
| null | ||
? T | ||
: DeepUnReadonlyObject<T>; | ||
type DeepUnReadonly<T> = T extends object ? DeepUnReadonlyObject<T> : T; | ||
type DeepUnReadonlyObject<T> = { | ||
@@ -422,0 +393,0 @@ -readonly [P in keyof T]: DeepUnReadonly<T[P]>; |
{ | ||
"name": "as-typed", | ||
"version": "0.0.0-dev.20201229022322", | ||
"version": "0.0.0-dev.20201229023359", | ||
"description": "Static TypeScript types from a literal JSONSchema type", | ||
@@ -5,0 +5,0 @@ "types": "index.d.ts", |
35754
920