Comparing version 1.1.0 to 1.1.1
@@ -5,5 +5,6 @@ declare namespace AsTypedInternal { | ||
$ref?: string; | ||
type?: string; | ||
type?: string | string[]; | ||
title?: string; | ||
description?: string; | ||
nullable?: boolean; | ||
default?: any; | ||
@@ -215,5 +216,7 @@ examples?: any[]; | ||
type ResolveRecursiveInternal< | ||
SchemaType | ||
> = SchemaType extends SchemaDeclaration<null> | ||
type ResolveRecursiveInternal<SchemaType> = SchemaType extends { | ||
nullable: true; | ||
} | ||
? ResolveRecursiveInternal<Omit<SchemaType, "nullable">> | null | ||
: SchemaType extends SchemaDeclaration<null> | ||
? null | ||
@@ -242,2 +245,12 @@ : SchemaType extends ConstSchema<infer Value> | ||
? ResolveArray<ValueType> | ||
: SchemaType extends { | ||
type: [infer Type]; | ||
} | ||
? ResolveRecursiveInternal<Omit<SchemaType, "type"> & { type: Type }> | ||
: SchemaType extends { | ||
type: [infer Type, ...infer Rest]; | ||
} | ||
? | ||
| ResolveRecursiveInternal<Omit<SchemaType, "type"> & { type: Type }> | ||
| ResolveRecursiveInternal<Omit<SchemaType, "type"> & { type: Rest }> | ||
: never; | ||
@@ -244,0 +257,0 @@ |
{ | ||
"name": "as-typed", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Static TypeScript types from a literal JSONSchema type", | ||
@@ -31,14 +31,14 @@ "types": "index.d.ts", | ||
"devDependencies": { | ||
"@typescript-eslint/eslint-plugin": "^4.8.2", | ||
"@typescript-eslint/parser": "^4.8.2", | ||
"@typescript-eslint/typescript-estree": "^4.8.2", | ||
"eslint": "^7.14.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"@typescript-eslint/eslint-plugin": "^4.11.0", | ||
"@typescript-eslint/parser": "^4.11.0", | ||
"@typescript-eslint/typescript-estree": "^4.11.0", | ||
"eslint": "^7.16.0", | ||
"eslint-config-prettier": "^7.1.0", | ||
"eslint-plugin-import": "^2.20.2", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"prettier": "^2.2.0", | ||
"eslint-plugin-prettier": "^3.3.0", | ||
"prettier": "^2.2.1", | ||
"spec.ts": "^1.1.3", | ||
"ts-node": "^9.0.0", | ||
"typescript": "^4.1.2" | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.1.3" | ||
} | ||
} |
19
test.ts
@@ -14,2 +14,8 @@ import { AsTyped } from "./index"; | ||
assert(_ as AsTyped<{ type: ["string", "null"] }>, _ as string | null); | ||
assert(_ as AsTyped<{ type: "string"; nullable: true }>, _ as string | null); | ||
assert(_ as AsTyped<{ type: "string"; nullable: false }>, _ as string); | ||
assert(_ as AsTyped<{ type: "boolean" }>, _ as boolean); | ||
@@ -186,2 +192,15 @@ | ||
assert( | ||
_ as AsTyped<{ | ||
type: ["object", "boolean", "null"]; | ||
properties: { | ||
arr: { | ||
type: "array"; | ||
items: { type: "object"; additionalProperties: { type: "string" } }; | ||
}; | ||
}; | ||
}>, | ||
_ as { arr?: Array<{ [name: string]: string }> } | boolean | null | ||
); | ||
/* | ||
@@ -188,0 +207,0 @@ * assert( |
35566
921