From 680e1ede9801a00a6cae27176f9515ad0bddc026 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Wed, 8 Jun 2022 10:26:29 -0400 Subject: [PATCH] Fix type errors Signed-off-by: Sebastian Malton --- .../utils/sync-box/create-sync-box.injectable.ts | 13 +++++-------- .../utils/sync-box/sync-box-injection-token.ts | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/common/utils/sync-box/create-sync-box.injectable.ts b/src/common/utils/sync-box/create-sync-box.injectable.ts index 4b15fdb79f..28a0ec3ccb 100644 --- a/src/common/utils/sync-box/create-sync-box.injectable.ts +++ b/src/common/utils/sync-box/create-sync-box.injectable.ts @@ -3,11 +3,12 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ import { getInjectable } from "@ogre-tools/injectable"; +import type { IObservableValue } from "mobx"; import { computed } from "mobx"; import syncBoxChannelInjectable from "./sync-box-channel.injectable"; import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token"; import syncBoxStateInjectable from "./sync-box-state.injectable"; -import type { SyncBox } from "./sync-box-injection-token"; +import type { AsJson, SyncBox } from "./sync-box-injection-token"; const createSyncBoxInjectable = getInjectable({ id: "create-sync-box", @@ -17,19 +18,15 @@ const createSyncBoxInjectable = getInjectable({ const messageToChannel = di.inject(messageToChannelInjectionToken); const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id); - return (id: string, initialValue: TData): SyncBox => { - const state = getSyncBoxState(id); + return (id: string, initialValue: AsJson): SyncBox => { + const state = getSyncBoxState(id) as IObservableValue>; state.set(initialValue); return { id, - /** - * SAFETY: we unconditionally set the value above and only allow `TData` with the `.set` - * function so this is always `TData`. - */ - value: computed(() => state.get() as TData), + value: computed(() => state.get()), set: (value) => { state.set(value); diff --git a/src/common/utils/sync-box/sync-box-injection-token.ts b/src/common/utils/sync-box/sync-box-injection-token.ts index 76ba0679f3..347e4d85fa 100644 --- a/src/common/utils/sync-box/sync-box-injection-token.ts +++ b/src/common/utils/sync-box/sync-box-injection-token.ts @@ -5,7 +5,7 @@ import { getInjectionToken } from "@ogre-tools/injectable"; import type { IComputedValue } from "mobx"; -type AsJson = T extends string | number | boolean | null +export type AsJson = T extends string | number | boolean | null ? T : T extends Function ? never