DefinitelyTyped/types/json-schema-merge-allof/json-schema-merge-allof-tests.ts
Emily Marigold Klassen f2e14c8f84 Add typings for json-schema-merge-allof (#39444)
* Add typings for json-schema-merge-allof

* Fix lint issues

* Specifically add a 4 | 6 JSONSchema type for json-schema-ref-parser usage

* Add tests and further refine types
2019-10-25 15:53:43 -07:00

29 lines
814 B
TypeScript

import mergeAllOf = require('json-schema-merge-allof');
import { JSONSchema4, JSONSchema6 } from 'json-schema';
type $RefParser_JSONSchema = JSONSchema4 | JSONSchema6;
const schema: $RefParser_JSONSchema = { type: 'string' };
mergeAllOf(schema);
type JSONSchemaExtra = JSONSchema6 & {
[key: string]: any;
};
const schemaExtra: JSONSchemaExtra = { type: 'string' };
// $ExpectType JSONSchema6
mergeAllOf(schemaExtra);
// $ExpectType JSONSchemaExtra
mergeAllOf(schemaExtra, { ignoreAdditionalProperties: true, resolvers: {
oneOf(values, path, mergeSchemas, options) {
// $ExpectType (JSONSchema6Definition[] | undefined)[]
values;
// $ExpectType Options<JSONSchemaExtra>
options;
return values.reduce((prev, next) => (prev || []).concat(next || []))!;
}
} });