aboutsummaryrefslogtreecommitdiff
path: root/src/fields/Proxy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields/Proxy.ts')
-rw-r--r--src/fields/Proxy.ts31
1 files changed, 16 insertions, 15 deletions
diff --git a/src/fields/Proxy.ts b/src/fields/Proxy.ts
index 83b5672b3..48c336e60 100644
--- a/src/fields/Proxy.ts
+++ b/src/fields/Proxy.ts
@@ -3,18 +3,19 @@ import { primitive, serializable } from 'serializr';
import { DocServer } from '../client/DocServer';
import { scriptingGlobal } from '../client/util/ScriptingGlobals';
import { Deserializable } from '../client/util/SerializationHelper';
-import { Field, FieldWaiting, Opt } from './Doc';
+import { Doc, Field, FieldWaiting, Opt } from './Doc';
import { Copy, Id, ToJavascriptString, ToScriptString, ToString, ToValue } from './FieldSymbols';
import { ObjectField } from './ObjectField';
-import { RefField } from './RefField';
-function deserializeProxy(field: any) {
+type serializedProxyType = { cache: { field: unknown; p: undefined | Promise<unknown> }; fieldId: string };
+
+function deserializeProxy(field: serializedProxyType) {
if (!field.cache.field) {
- field.cache = { field: DocServer.GetCachedRefField(field.fieldId) as any, p: undefined };
+ field.cache = { field: DocServer.GetCachedRefField(field.fieldId), p: undefined };
}
}
-@Deserializable('proxy', deserializeProxy)
-export class ProxyField<T extends RefField> extends ObjectField {
+@Deserializable('proxy', (obj: unknown) => deserializeProxy(obj as serializedProxyType))
+export class ProxyField<T extends Doc> extends ObjectField {
constructor();
constructor(value: T);
constructor(fieldId: string);
@@ -39,10 +40,10 @@ export class ProxyField<T extends RefField> extends ObjectField {
}
[ToJavascriptString]() {
- return Field.toScriptString(this[ToValue]()?.value);
+ return Field.toScriptString(this[ToValue]()?.value as T);
}
[ToScriptString]() {
- return Field.toScriptString(this[ToValue]()?.value); // not sure this is quite right since it doesn't recreate a proxy field, but better than 'invalid' ?
+ return Field.toScriptString(this[ToValue]()?.value as T); // not sure this is quite right since it doesn't recreate a proxy field, but better than 'invalid' ?
}
[ToString]() {
return Field.toString(this[ToValue]()?.value);
@@ -83,7 +84,7 @@ export class ProxyField<T extends RefField> extends ObjectField {
return !!(!this.cache.field && !this.failed && !this._cache.p && !DocServer.GetCachedRefField(this.fieldId));
}
- setExternalValuePromise(externalValuePromise: Promise<any>) {
+ setExternalValuePromise(externalValuePromise: Promise<unknown>) {
this.cache.p = externalValuePromise.then(() => this.value) as FieldWaiting<T>;
}
@action
@@ -94,7 +95,7 @@ export class ProxyField<T extends RefField> extends ObjectField {
}
}
-// eslint-disable-next-line no-redeclare
+// eslint-disable-next-line no-redeclare, @typescript-eslint/no-namespace
export namespace ProxyField {
let useProxy = true;
export function DisableProxyFields() {
@@ -114,7 +115,7 @@ export namespace ProxyField {
}
}
- export function toValue(value: any) {
+ export function toValue(value: { value: unknown }) {
if (useProxy) {
return { value: value.value };
}
@@ -123,10 +124,10 @@ export namespace ProxyField {
}
// eslint-disable-next-line no-use-before-define
-function prefetchValue(proxy: PrefetchProxy<RefField>) {
- return proxy.value as any;
+function prefetchValue(proxy: PrefetchProxy<Doc>) {
+ return proxy.value as Promise<Doc>;
}
@scriptingGlobal
-@Deserializable('prefetch_proxy', prefetchValue)
-export class PrefetchProxy<T extends RefField> extends ProxyField<T> {}
+@Deserializable('prefetch_proxy', (obj:unknown) => prefetchValue(obj as PrefetchProxy<Doc>))
+export class PrefetchProxy<T extends Doc> extends ProxyField<T> {}