json-schema-ts
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -174,4 +174,4 @@ export namespace t { | ||
type TSTypeNoRef<T> = T extends true ? true | ||
: T extends false ? false | ||
type TSTypeNoRef<T> = T extends true ? any | ||
: T extends false ? never | ||
: T extends StringType<infer U> ? U | ||
@@ -190,3 +190,3 @@ : T extends NumberType<infer U> ? U | ||
: T extends AllOfType<infer T> ? { [K in keyof T]: TSType<T[K]> }[number] | ||
: never | ||
: never; | ||
@@ -193,0 +193,0 @@ export type TSType<T> = T extends RefType<infer S> ? TSTypeNoRef<S> : TSTypeNoRef<T> |
{ | ||
"name": "json-schema-ts", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "JSON schema types for TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
50
test.js
@@ -18,2 +18,9 @@ "use strict"; | ||
{ | ||
var the_true = true; | ||
meta.equal(true); | ||
} | ||
{ | ||
var the_false = false; | ||
} | ||
{ | ||
var the_string = index_1.s.string({ | ||
@@ -60,10 +67,29 @@ 'default': 'test', | ||
var the_array = index_1.s.array({ | ||
default: [], | ||
'default': [], | ||
'items': index_1.s.string(), | ||
}); | ||
meta.equal(true); | ||
// meta.equal<T, number[]>(false); | ||
meta.equal(true); | ||
meta.equal(false); | ||
meta.equal(false); | ||
(function (_x) { })([]); | ||
} | ||
{ | ||
var the_array = index_1.s.array({ | ||
'items': true, | ||
}); | ||
meta.equal(true); | ||
meta.equal(true); | ||
// any extends string, and string extends any | ||
meta.equal(true); | ||
meta.equal(false); | ||
(function (_x) { })([]); | ||
} | ||
{ | ||
var the_array = index_1.s.array({ | ||
'items': false, | ||
}); | ||
// FIXME: how to test never? | ||
} | ||
{ | ||
var the_object = index_1.s.object({ | ||
@@ -75,2 +101,3 @@ 'default': {}, | ||
meta.equal(false); | ||
meta.equal(false); | ||
(function (_x) { })({}); | ||
@@ -90,5 +117,13 @@ } | ||
} | ||
}), true, false); | ||
}), true); | ||
var tuple = index_1.s.tuple({ 'items': items }); | ||
(function (_x) { })(['a', 2, 2, true, {}, { 'hello': 'haha' }, true, false]); | ||
(function (_x) { })([ | ||
'a', | ||
2, | ||
2, | ||
true, | ||
{}, | ||
{ 'hello': 'haha' }, | ||
['asas', 1, true, false, {}], | ||
]); | ||
} | ||
@@ -133,3 +168,3 @@ { | ||
'true': true, | ||
'false': false, | ||
// 'false': false, | ||
'ref': index_1.s.ref('hello', refObject), | ||
@@ -149,4 +184,4 @@ }, | ||
'tuple': ['hello', 1, { 'hello': 'string' }], | ||
'true': true, | ||
'false': false, | ||
'true': ['hello', 1, true, false], | ||
// 'false': false, | ||
'ref': { | ||
@@ -167,3 +202,2 @@ 'ref_object': [1, 2], | ||
'name': index_1.s.string(), | ||
// [first name, last name] | ||
'fullName': index_1.s.object({ 'properties': { | ||
@@ -170,0 +204,0 @@ 'firstName': index_1.s.string(), |
60
test.ts
@@ -19,2 +19,13 @@ import {t, s} from './index'; | ||
{ | ||
const the_true = true; | ||
type T = t.TSType<typeof the_true>; | ||
meta.equal<T, any>(true); | ||
} | ||
{ | ||
const the_false = false; | ||
type T = t.TSType<typeof the_false>; | ||
} | ||
{ | ||
const the_string = s.string({ | ||
@@ -75,7 +86,24 @@ 'default': 'test', | ||
const the_array = s.array({ | ||
default: [], | ||
'default': [], | ||
'items': s.string(), | ||
}); | ||
type T = t.TSType<typeof the_array>; | ||
type a = T[number]; | ||
meta.equal<a, string>(true); | ||
meta.equal<T, string[]>(true); | ||
meta.equal<T, number[]>(false); | ||
meta.equal<T, [any, any]>(false); | ||
((_x: T) => {})([]); | ||
} | ||
{ | ||
const the_array = s.array({ | ||
'items': true, | ||
}); | ||
type T = t.TSType<typeof the_array>; | ||
type a = T[number]; | ||
meta.equal<a, any>(true); | ||
meta.equal<T, any[]>(true); | ||
// meta.equal<T, number[]>(false); | ||
// any extends string, and string extends any | ||
meta.equal<T, string[]>(true); | ||
meta.equal<T, [any, any]>(false); | ||
@@ -86,2 +114,11 @@ ((_x: T) => {})([]); | ||
{ | ||
const the_array = s.array({ | ||
'items': false, | ||
}); | ||
type T = t.TSType<typeof the_array>; | ||
type a = T[number]; | ||
// FIXME: how to test never? | ||
} | ||
{ | ||
const the_object = s.object({ | ||
@@ -94,2 +131,3 @@ 'default': {}, | ||
meta.equal<T, any[]>(false); | ||
meta.equal<T, string>(false); | ||
((_x: T) => {})({}); | ||
@@ -120,3 +158,3 @@ } | ||
true, | ||
false, | ||
// false, | ||
); | ||
@@ -127,3 +165,11 @@ | ||
((_x: T) => {})(['a', 2, 2, true, {}, {'hello': 'haha'}, true, false]); | ||
((_x: T) => {})([ | ||
'a', | ||
2, | ||
2, | ||
true, | ||
{}, | ||
{'hello': 'haha'}, | ||
['asas', 1, true, false, {}], | ||
]); | ||
} | ||
@@ -176,3 +222,3 @@ | ||
'true': true, | ||
'false': false, | ||
// 'false': false, | ||
'ref': s.ref('hello', refObject), | ||
@@ -194,4 +240,4 @@ }, | ||
'tuple': ['hello', 1, {'hello': 'string'}], | ||
'true': true, | ||
'false': false, | ||
'true': ['hello', 1, true, false], | ||
// 'false': false, | ||
'ref': { | ||
@@ -198,0 +244,0 @@ 'ref_object': [1, 2], |
32314
848