aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/Types.ts
diff options
context:
space:
mode:
authorFawn <fangrui_tong@brown.edu>2019-06-15 17:28:06 -0400
committerFawn <fangrui_tong@brown.edu>2019-06-15 17:28:06 -0400
commit14ae66aec1879386c130567496597db9105e4f99 (patch)
tree300f9ac7e153bd404b8b3799fba0f52514861c36 /src/new_fields/Types.ts
parentb4bd43f6e79c9dec30842262f270ca6122f1184a (diff)
parent618d3717e118f978de976cb34e8bc2051c726ffc (diff)
merge with master
Diffstat (limited to 'src/new_fields/Types.ts')
-rw-r--r--src/new_fields/Types.ts8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/new_fields/Types.ts b/src/new_fields/Types.ts
index c04dd5e6d..8dd893aa4 100644
--- a/src/new_fields/Types.ts
+++ b/src/new_fields/Types.ts
@@ -2,7 +2,7 @@ import { Field, Opt, FieldResult, Doc } from "./Doc";
import { List } from "./List";
import { RefField } from "./RefField";
-export type ToType<T extends ToConstructor<Field> | ListSpec<Field> | DefaultFieldConstructor<Field>> =
+export type ToType<T extends InterfaceValue> =
T extends "string" ? string :
T extends "number" ? number :
T extends "boolean" ? boolean :
@@ -10,7 +10,8 @@ export type ToType<T extends ToConstructor<Field> | ListSpec<Field> | DefaultFie
// T extends { new(...args: any[]): infer R } ? (R | Promise<R>) : never;
T extends DefaultFieldConstructor<infer _U> ? never :
T extends { new(...args: any[]): List<Field> } ? never :
- T extends { new(...args: any[]): infer R } ? R : never;
+ T extends { new(...args: any[]): infer R } ? R :
+ T extends (doc?: Doc) => infer R ? R : never;
export type ToConstructor<T extends Field> =
T extends string ? "string" :
@@ -38,9 +39,10 @@ export type Tail<T extends any[]> =
((...t: T) => any) extends ((_: any, ...tail: infer TT) => any) ? TT : [];
export type HasTail<T extends any[]> = T extends ([] | [any]) ? false : true;
+export type InterfaceValue = ToConstructor<Field> | ListSpec<Field> | DefaultFieldConstructor<Field> | ((doc?: Doc) => any);
//TODO Allow you to optionally specify default values for schemas, which should then make that field not be partial
export interface Interface {
- [key: string]: ToConstructor<Field> | ListSpec<Field> | DefaultFieldConstructor<Field>;
+ [key: string]: InterfaceValue;
// [key: string]: ToConstructor<Field> | ListSpec<Field[]>;
}