summaryrefslogtreecommitdiffhomepage
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/types/JSONStream/index.d.ts22
-rw-r--r--gui/types/validated/index.d.ts105
2 files changed, 96 insertions, 31 deletions
diff --git a/gui/types/JSONStream/index.d.ts b/gui/types/JSONStream/index.d.ts
index 094c53ed6a..622cf71cf5 100644
--- a/gui/types/JSONStream/index.d.ts
+++ b/gui/types/JSONStream/index.d.ts
@@ -5,15 +5,13 @@
/// <reference types="node" />
-
-declare module "JSONStream" {
+declare module 'JSONStream' {
export interface Options {
- recurse: boolean;
+ recurse: boolean;
}
- export declare function parse(pattern: any): NodeJS.ReadWriteStream;
- export declare function parse(patterns: any[]): NodeJS.ReadWriteStream;
-
+ export function parse(pattern: any): NodeJS.ReadWriteStream;
+ export function parse(patterns: any[]): NodeJS.ReadWriteStream;
/**
* Create a writable stream.
@@ -21,11 +19,11 @@ declare module "JSONStream" {
* JSONStream.stringify() will create an array,
* (with default options open='[\n', sep='\n,\n', close='\n]\n')
*/
- export declare function stringify(): NodeJS.ReadWriteStream;
+ export function stringify(): NodeJS.ReadWriteStream;
/** If you call JSONStream.stringify(false) the elements will only be seperated by a newline. */
- export declare function stringify(newlineOnly: NewlineOnlyIndicator): NodeJS.ReadWriteStream;
- type NewlineOnlyIndicator = false
+ export function stringify(newlineOnly: NewlineOnlyIndicator): NodeJS.ReadWriteStream;
+ type NewlineOnlyIndicator = false;
/**
* Create a writable stream.
@@ -33,8 +31,8 @@ declare module "JSONStream" {
* JSONStream.stringify() will create an array,
* (with default options open='[\n', sep='\n,\n', close='\n]\n')
*/
- export declare function stringify(open: string, sep: string, close: string): NodeJS.ReadWriteStream;
+ export function stringify(open: string, sep: string, close: string): NodeJS.ReadWriteStream;
- export declare function stringifyObject(): NodeJS.ReadWriteStream;
- export declare function stringifyObject(open: string, sep: string, close: string): NodeJS.ReadWriteStream;
+ export function stringifyObject(): NodeJS.ReadWriteStream;
+ export function stringifyObject(open: string, sep: string, close: string): NodeJS.ReadWriteStream;
}
diff --git a/gui/types/validated/index.d.ts b/gui/types/validated/index.d.ts
index a70536df8c..5fb1da1241 100644
--- a/gui/types/validated/index.d.ts
+++ b/gui/types/validated/index.d.ts
@@ -1,5 +1,7 @@
-// TypeScript typings for validated
-// https://github.com/andreypopp/validated
+// Type definitions for validated 2.0.1
+// Project: https://github.com/andreypopp/validated
+// Definitions by: Andrej Mihajlov <https://github.com/pronebird>
+// TypeScript Version: 3.3.3
declare module 'validated/schema' {
export interface Context {}
@@ -8,35 +10,100 @@ declare module 'validated/schema' {
value: T;
}
+ // Cyclic refs issue when unnesting arrays with complex types
+ // https://github.com/Microsoft/TypeScript/issues/14174
+ type ExtractNodeType<T> = T extends Node<infer S>
+ ? S extends { [name: string]: Node<infer _> }
+ ? { [K in keyof S]: ExtractNodeType<S[K]> }
+ : S extends Array<infer U>
+ ? U[] // Array<ExtractNodeType<U>>
+ : S
+ : T;
+
export class Node<T> {
- validate(context: Context): ValidateResult<T>;
+ validate(context: Context): ValidateResult<ExtractNodeType<Node<T>>>;
}
- type NodeDict<T> = { [name: string]: Node<T> };
+ type NodeDict = { [name: string]: Node<unknown> };
- export function object<T, S extends NodeDict<T>>(values: S, defaults?: Object): Node<S>;
- export function partialObject<T, S extends NodeDict<T>>(values: S, defaults?: Object): Node<S>;
- export function maybe<T>(valueNode: Node<T>): Node<T>;
+ export function object<T, S extends NodeDict>(values: S, defaults?: Object): Node<S>;
+ export function partialObject<T, S extends NodeDict>(values: S, defaults?: Object): Node<S>;
+ export function maybe<T>(valueNode: Node<T>): Node<T | undefined | null>;
export const string: Node<string>;
export const number: Node<number>;
export const boolean: Node<boolean>;
-
export function enumeration<T>(...values: Array<T>): Node<T>;
- export function arrayOf<T>(node: Node<T>): Node<T>;
+ export function arrayOf<T>(node: Node<T>): Node<Array<T>>;
+
+ export function oneOf<A, B>(a: Node<A>, b: Node<B>): Node<A | B>;
+
+ export function oneOf<A, B, C>(a: Node<A>, b: Node<B>, c: Node<C>): Node<A | B | C>;
+
+ export function oneOf<A, B, C, D>(
+ a: Node<A>,
+ b: Node<B>,
+ c: Node<C>,
+ d: Node<D>,
+ ): Node<A | B | C | D>;
+
+ export function oneOf<A, B, C, D, E>(
+ a: Node<A>,
+ b: Node<B>,
+ c: Node<C>,
+ d: Node<D>,
+ e: Node<E>,
+ ): Node<A | B | C | D | E | F | G | H>;
+
+ export function oneOf<A, B, C, D, E, F>(
+ a: Node<A>,
+ b: Node<B>,
+ c: Node<C>,
+ d: Node<D>,
+ e: Node<E>,
+ f: Node<F>,
+ ): Node<A | B | C | D | E | F>;
+
+ export function oneOf<A, B, C, D, E, F, G>(
+ a: Node<A>,
+ b: Node<B>,
+ c: Node<C>,
+ d: Node<D>,
+ e: Node<E>,
+ f: Node<F>,
+ g: Node<G>,
+ ): Node<A | B | C | D | E | F | G>;
+
export function oneOf<A, B, C, D, E, F, G, H>(
a: Node<A>,
- b?: Node<B>,
- c?: Node<C>,
- d?: Node<D>,
- e?: Node<E>,
- f?: Node<F>,
- g?: Node<G>,
- h?: Node<H>,
+ b: Node<B>,
+ c: Node<C>,
+ d: Node<D>,
+ e: Node<E>,
+ f: Node<F>,
+ g: Node<G>,
+ h: Node<H>,
): Node<A | B | C | D | E | F | G | H>;
+
+ export function oneOf<A, B, C, D, E, F, G, H, I>(
+ a: Node<A>,
+ b: Node<B>,
+ c: Node<C>,
+ d: Node<D>,
+ e: Node<E>,
+ f: Node<F>,
+ g: Node<G>,
+ h: Node<H>,
+ i: Node<I>,
+ ): Node<A | B | C | D | E | F | G | H | I>;
}
declare module 'validated/object' {
- export function validate<T>(object: Node<T>, value: any): T {
- return object.validate(new Context()).value;
- }
+ import { Node, ValidateResult } from 'validated/schema';
+
+ type ExtractValidateResult<T> = ReturnType<T> extends ValidateResult<infer V> ? V : never;
+
+ export function validate<T>(
+ object: Node<T>,
+ value: any,
+ ): ExtractValidateResult<typeof object.validate>;
}