mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix type errors
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
469f54b594
commit
680e1ede98
@ -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 <TData>(id: string, initialValue: TData): SyncBox<TData> => {
|
||||
const state = getSyncBoxState(id);
|
||||
return <TData>(id: string, initialValue: AsJson<TData>): SyncBox<TData> => {
|
||||
const state = getSyncBoxState(id) as IObservableValue<AsJson<TData>>;
|
||||
|
||||
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);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
|
||||
type AsJson<T> = T extends string | number | boolean | null
|
||||
export type AsJson<T> = T extends string | number | boolean | null
|
||||
? T
|
||||
: T extends Function
|
||||
? never
|
||||
|
||||
Loading…
Reference in New Issue
Block a user