aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Types.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields/Types.ts')
-rw-r--r--src/fields/Types.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/fields/Types.ts b/src/fields/Types.ts
index c90f3b6b3..bf40a0d7b 100644
--- a/src/fields/Types.ts
+++ b/src/fields/Types.ts
@@ -4,6 +4,8 @@ import { RefField } from "./RefField";
import { DateField } from "./DateField";
import { ScriptField } from "./ScriptField";
import { URLField, WebField, ImageField } from "./URLField";
+import { TextField } from "@material-ui/core";
+import { RichTextField } from "./RichTextField";
export type ToType<T extends InterfaceValue> =
T extends "string" ? string :
@@ -74,6 +76,10 @@ export function Cast<T extends CastCtor>(field: FieldResult, ctor: T, defaultVal
return defaultVal === null ? undefined : defaultVal;
}
+export function DocCast(field: FieldResult, defaultVal?: Doc) {
+ return Cast(field, Doc, null) ?? defaultVal;
+}
+
export function NumCast(field: FieldResult, defaultVal: number | null = 0) {
return Cast(field, "number", defaultVal);
}
@@ -88,6 +94,9 @@ export function BoolCast(field: FieldResult, defaultVal: boolean | null = false)
export function DateCast(field: FieldResult) {
return Cast(field, DateField, null);
}
+export function RTFCast(field: FieldResult) {
+ return Cast(field, RichTextField, null);
+}
export function ScriptCast(field: FieldResult, defaultVal: ScriptField | null = null) {
return Cast(field, ScriptField, defaultVal);