diff options
author | Aubrey Li <Aubrey-Li> | 2022-03-17 16:46:15 -0400 |
---|---|---|
committer | Aubrey Li <Aubrey-Li> | 2022-03-17 16:46:15 -0400 |
commit | 4e826c06bf3141f4561692f8565476db287f6135 (patch) | |
tree | 2bd0da7a72f11058f03bb1d4b911ef531ad3d32b /src/fields/Types.ts | |
parent | 33cb4ee1c5a6ff07f2c1096d94259c0e2999f1c1 (diff) | |
parent | 73ba1a0395167ab5949f71d0c82fa7188d37ab5c (diff) |
Merge remote-tracking branch 'origin/speedups2' into presentation_upgrade
Diffstat (limited to 'src/fields/Types.ts')
-rw-r--r-- | src/fields/Types.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/fields/Types.ts b/src/fields/Types.ts index 3d784448d..c90f3b6b3 100644 --- a/src/fields/Types.ts +++ b/src/fields/Types.ts @@ -3,6 +3,7 @@ import { List } from "./List"; import { RefField } from "./RefField"; import { DateField } from "./DateField"; import { ScriptField } from "./ScriptField"; +import { URLField, WebField, ImageField } from "./URLField"; export type ToType<T extends InterfaceValue> = T extends "string" ? string : @@ -91,6 +92,12 @@ export function DateCast(field: FieldResult) { export function ScriptCast(field: FieldResult, defaultVal: ScriptField | null = null) { return Cast(field, ScriptField, defaultVal); } +export function WebCast(field: FieldResult, defaultVal: WebField | null = null) { + return Cast(field, WebField, defaultVal); +} +export function ImageCast(field: FieldResult, defaultVal: ImageField | null = null) { + return Cast(field, ImageField, defaultVal); +} type WithoutList<T extends Field> = T extends List<infer R> ? (R extends RefField ? (R | Promise<R>)[] : R[]) : T; @@ -104,5 +111,6 @@ export interface PromiseLike<T> { then(callback: (field: Opt<T>) => void): void; } export function PromiseValue<T extends Field>(field: FieldResult<T>): PromiseLike<Opt<T>> { - return field instanceof Promise ? field : { then(cb: ((field: Opt<T>) => void)) { return cb(field); } }; + if (field instanceof Promise) return field as Promise<Opt<T>>; + return { then(cb: ((field: Opt<T>) => void)) { return cb(field); } }; }
\ No newline at end of file |