Fix to explicitly set Type Class field

This commit is contained in:
segayuu
2017-11-14 10:14:36 +09:00
parent 5fb500e9bc
commit a70ad3ce5d
2 changed files with 26 additions and 7 deletions
+11 -6
View File
@@ -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
+15 -1
View File
@@ -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);