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.
|
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
|
import type { IObservableValue } from "mobx";
|
||||||
import { computed } from "mobx";
|
import { computed } from "mobx";
|
||||||
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
|
import syncBoxChannelInjectable from "./sync-box-channel.injectable";
|
||||||
import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token";
|
import { messageToChannelInjectionToken } from "../channel/message-to-channel-injection-token";
|
||||||
import syncBoxStateInjectable from "./sync-box-state.injectable";
|
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({
|
const createSyncBoxInjectable = getInjectable({
|
||||||
id: "create-sync-box",
|
id: "create-sync-box",
|
||||||
@ -17,19 +18,15 @@ const createSyncBoxInjectable = getInjectable({
|
|||||||
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
||||||
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
const getSyncBoxState = (id: string) => di.inject(syncBoxStateInjectable, id);
|
||||||
|
|
||||||
return <TData>(id: string, initialValue: TData): SyncBox<TData> => {
|
return <TData>(id: string, initialValue: AsJson<TData>): SyncBox<TData> => {
|
||||||
const state = getSyncBoxState(id);
|
const state = getSyncBoxState(id) as IObservableValue<AsJson<TData>>;
|
||||||
|
|
||||||
state.set(initialValue);
|
state.set(initialValue);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
|
|
||||||
/**
|
value: computed(() => state.get()),
|
||||||
* 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),
|
|
||||||
|
|
||||||
set: (value) => {
|
set: (value) => {
|
||||||
state.set(value);
|
state.set(value);
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||||
import type { IComputedValue } from "mobx";
|
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
|
||||||
: T extends Function
|
: T extends Function
|
||||||
? never
|
? never
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user