From a70ad3ce5d4affd8e3fe0c545361d8f01c7c3137 Mon Sep 17 00:00:00 2001 From: segayuu Date: Tue, 14 Nov 2017 10:14:36 +0900 Subject: [PATCH] Fix to explicitly set Type Class field --- types/js-yaml/index.d.ts | 17 +++++++++++------ types/js-yaml/js-yaml-tests.ts | 16 +++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/types/js-yaml/index.d.ts b/types/js-yaml/index.d.ts index 98354d26ba..51f3ae95cf 100644 --- a/types/js-yaml/index.d.ts +++ b/types/js-yaml/index.d.ts @@ -7,12 +7,17 @@ export function safeLoad(str: string, opts?: LoadOptions): any; export function load(str: string, opts?: LoadOptions): any; -export class Type { +export class Type implements TypeConstructorOptions { constructor(tag: string, opts?: TypeConstructorOptions); - tag: string; + kind: string | null; + resolve(data: any): boolean; + construct(data: any): any; + instanceOf: object | null; + predicate: string | null; + represent: ((data: object) => any) | { [x: string]: (data: object) => any; } | null; + defaultStyle: string | null; + styleAliases: { [x: string]: any; }; } -/* tslint:disable-next-line:no-empty-interface */ -export interface Type extends TypeConstructorOptions { } /* tslint:disable-next-line:no-unnecessary-class */ export class Schema implements SchemaDefinition { @@ -73,8 +78,8 @@ export interface TypeConstructorOptions { export interface SchemaDefinition { implicit?: any[]; - explicit?: any[]; - include?: any[]; + explicit?: Type[]; + include?: Schema[]; } // only strings, arrays and plain objects: http://www.yaml.org/spec/1.2/spec.html#id2802346 diff --git a/types/js-yaml/js-yaml-tests.ts b/types/js-yaml/js-yaml-tests.ts index 91229e487a..6799deafd8 100644 --- a/types/js-yaml/js-yaml-tests.ts +++ b/types/js-yaml/js-yaml-tests.ts @@ -7,10 +7,13 @@ import SchemaDefinition = yaml.SchemaDefinition; let bool: boolean; let num: number; let str: string; -let obj: { [x: string]: any; }; +let obj: object; +let map: { [x: string]: any; }; let value: any; let array: any[]; let fn: (...args: any[]) => any; +let fnOrFnMap: ((...args: any[]) => any) | { [x: string]: (...args: any[]) => any; }; +let type: yaml.Type; let schemaDefinition: SchemaDefinition = { implicit: array, explicit: array, @@ -72,6 +75,17 @@ dumpOpts = { // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +str = type.kind; +fn = type.resolve; +fn = type.construct; +obj = type.instanceOf; +str = type.predicate; +fnOrFnMap = type.represent; +str = type.defaultStyle; +map = type.styleAliases; + +// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + value = yaml.safeLoad(str); value = yaml.safeLoad(str, loadOpts);