Improved typing for player.layers

This commit is contained in:
thepaperpilot 2022-06-05 17:30:40 -05:00
parent b6d5eaa72d
commit 9370b0ed6f

View file

@ -3,6 +3,7 @@ import Decimal from "util/bignum";
import type { ProxiedWithState } from "util/proxies"; import type { ProxiedWithState } from "util/proxies";
import { ProxyPath, ProxyState } from "util/proxies"; import { ProxyPath, ProxyState } from "util/proxies";
import { reactive, unref } from "vue"; import { reactive, unref } from "vue";
import type { Ref } from "vue";
import transientState from "./state"; import transientState from "./state";
export interface PlayerData { export interface PlayerData {
@ -18,11 +19,23 @@ export interface PlayerData {
keepGoing: boolean; keepGoing: boolean;
modID: string; modID: string;
modVersion: string; modVersion: string;
layers: Record<string, Record<string, unknown>>; layers: Record<string, LayerData<unknown>>;
} }
export type Player = ProxiedWithState<PlayerData>; export type Player = ProxiedWithState<PlayerData>;
export type LayerData<T> = {
[P in keyof T]?: T[P] extends (infer U)[]
? LayerData<U>[]
: T[P] extends Record<string, never>
? never
: T[P] extends Ref<infer S>
? S
: T[P] extends object
? LayerData<T[P]>
: T[P];
};
const state = reactive<PlayerData>({ const state = reactive<PlayerData>({
id: "", id: "",
devSpeed: null, devSpeed: null,