json-schema-ts
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -46,3 +46,3 @@ "use strict"; | ||
function tuple(body) { | ||
return __assign({ 'type': 'array' }, body); | ||
return __assign({}, body, { 'type': 'array' }); | ||
} | ||
@@ -49,0 +49,0 @@ s.tuple = tuple; |
16
index.ts
@@ -181,10 +181,10 @@ export namespace t { | ||
: T extends NullType<infer U> ? U | ||
: T extends ArrayType<infer T> ? ArrayTSType<T> | ||
: T extends TupleType<infer T> ? MapToTSType<T> | ||
: T extends ObjectType<infer T> ? MapToTSType<T> | ||
: T extends ArrayType<infer U> ? ArrayTSType<U> | ||
: T extends TupleType<infer U> ? MapToTSType<U> | ||
: T extends ObjectType<infer U> ? MapToTSType<U> | ||
// tuple to union. See https://github.com/Microsoft/TypeScript/issues/13298#issuecomment-423385929 | ||
: T extends AnyOfType<infer T> ? { [K in keyof T]: TSType<T[K]> }[number] | ||
: T extends OneOfType<infer T> ? { [K in keyof T]: TSType<T[K]> }[number] | ||
: T extends AnyOfType<infer U> ? { [K in keyof U]: TSType<U[K]> }[number] | ||
: T extends OneOfType<infer U> ? { [K in keyof U]: TSType<U[K]> }[number] | ||
// FIXME: how to convert tuple to intersection type? | ||
: T extends AllOfType<infer T> ? { [K in keyof T]: TSType<T[K]> }[number] | ||
: T extends AllOfType<infer U> ? { [K in keyof U]: TSType<U[K]> }[number] | ||
: never; | ||
@@ -240,4 +240,4 @@ | ||
return { | ||
...body, | ||
'type': 'array', | ||
...body, | ||
}; | ||
@@ -283,2 +283,2 @@ } | ||
} | ||
} | ||
} |
{ | ||
"name": "json-schema-ts", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "JSON schema types for TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
35
test.js
@@ -92,4 +92,14 @@ "use strict"; | ||
} | ||
// FIXME: s.object() does not work | ||
// FIXME: s.object() doesn't work | ||
// { | ||
// const the_object = s.object(); | ||
// type T = t.TSType<typeof the_object>; | ||
// meta.equal<T, {}>(true); | ||
// // meta.equal<T, {[key: string]: number}>(false); | ||
// meta.equal<T, any[]>(false); | ||
// meta.equal<T, string>(false); | ||
// ((_x: T) => {})({}); | ||
// } | ||
// FIXME: s.object() doesn't work | ||
// { | ||
// const the_object = s.object({ | ||
@@ -106,2 +116,12 @@ // }); | ||
var the_object = index_1.s.object({ | ||
'properties': {} | ||
}); | ||
meta.equal(true); | ||
// meta.equal<T, {[key: string]: number}>(false); | ||
meta.equal(false); | ||
meta.equal(false); | ||
(function (_x) { })({}); | ||
} | ||
{ | ||
var the_object = index_1.s.object({ | ||
'default': {}, | ||
@@ -127,3 +147,3 @@ 'properties': { | ||
var items = index_1.s.items(index_1.s.string(), index_1.s.number(), index_1.s.integer(), index_1.s.boolean(), | ||
// FIXME | ||
// FIXME: s.object() doesn't work | ||
// s.object(), | ||
@@ -146,2 +166,13 @@ index_1.s.object({ | ||
} | ||
// FIXME: s.object() doesn't work | ||
// { | ||
// const items = s.items( | ||
// s.object(), | ||
// ); | ||
// const tuple = s.tuple({'items': items}); | ||
// type T = t.TSType<typeof tuple>; | ||
// ((_x: T) => {})([ | ||
// {}, | ||
// ]); | ||
// } | ||
{ | ||
@@ -148,0 +179,0 @@ var the_ref = index_1.s.ref('#/hello'); |
46
test.ts
@@ -120,4 +120,15 @@ import {t, s} from './index'; | ||
// FIXME: s.object() does not work | ||
// FIXME: s.object() doesn't work | ||
// { | ||
// const the_object = s.object(); | ||
// type T = t.TSType<typeof the_object>; | ||
// meta.equal<T, {}>(true); | ||
// // meta.equal<T, {[key: string]: number}>(false); | ||
// meta.equal<T, any[]>(false); | ||
// meta.equal<T, string>(false); | ||
// ((_x: T) => {})({}); | ||
// } | ||
// FIXME: s.object() doesn't work | ||
// { | ||
// const the_object = s.object({ | ||
@@ -135,2 +146,15 @@ // }); | ||
const the_object = s.object({ | ||
'properties': { | ||
} | ||
}); | ||
type T = t.TSType<typeof the_object>; | ||
meta.equal<T, {}>(true); | ||
// meta.equal<T, {[key: string]: number}>(false); | ||
meta.equal<T, any[]>(false); | ||
meta.equal<T, string>(false); | ||
((_x: T) => {})({}); | ||
} | ||
{ | ||
const the_object = s.object({ | ||
'default': {}, | ||
@@ -164,3 +188,3 @@ 'properties': { | ||
s.boolean(), | ||
// FIXME | ||
// FIXME: s.object() doesn't work | ||
// s.object(), | ||
@@ -187,5 +211,19 @@ s.object({ | ||
['asas', 1, true, false, {}], | ||
]); | ||
]); | ||
} | ||
// FIXME: s.object() doesn't work | ||
// { | ||
// const items = s.items( | ||
// s.object(), | ||
// ); | ||
// const tuple = s.tuple({'items': items}); | ||
// type T = t.TSType<typeof tuple>; | ||
// ((_x: T) => {})([ | ||
// {}, | ||
// ]); | ||
// } | ||
{ | ||
@@ -304,2 +342,2 @@ const the_ref = s.ref<t.NumberType>('#/hello'); | ||
meta.equal<IPerson, IPerson2>(true); | ||
} | ||
} |
41189
10
1176