diff --git a/src/device-state.ts b/src/device-state.ts index 67baec89..825ad09d 100644 --- a/src/device-state.ts +++ b/src/device-state.ts @@ -70,12 +70,16 @@ function validateState(state: any): asserts state is TargetState { if (!_.isObject(state)) { throw new Error('State must be an object'); } - if (!_.isObject(state.local)) { + // these any typings seem unnecessary but the `isObject` + // call above tells typescript that state is of type + // `object` - which apparently does not allow any fields + // to be accessed + if (!_.isObject((state as any).local)) { throw new Error('Local state must be an object'); } - validateLocalState(state.local); - if (state.dependent != null) { - return validateDependentState(state.dependent); + validateLocalState((state as any).local); + if ((state as any).dependent != null) { + return validateDependentState((state as any).dependent); } } diff --git a/src/device-state/preload.ts b/src/device-state/preload.ts index 78b2900d..f89237b2 100644 --- a/src/device-state/preload.ts +++ b/src/device-state/preload.ts @@ -34,7 +34,7 @@ export async function loadTargetFromFile( if (_.isArray(stateFromFile)) { log.debug('Detected a legacy apps.json, converting...'); - stateFromFile = convertLegacyAppsJson(stateFromFile); + stateFromFile = convertLegacyAppsJson(stateFromFile as any[]); } const preloadState = stateFromFile as AppsJsonFormat; @@ -80,12 +80,15 @@ export async function loadTargetFromFile( preloadState.config, ); preloadState.config = { ...formattedConf, ...deviceConf }; - const localState = { local: { name: '', ...preloadState } }; + const localState = { + local: { name: '', ...preloadState }, + dependent: { apps: [], devices: [] }, + }; await deviceState.setTarget(localState); log.success('Preloading complete'); - if (stateFromFile.pinDevice) { + if (preloadState.pinDevice) { // Multi-app warning! // The following will need to be changed once running // multiple applications is possible diff --git a/src/types/state.ts b/src/types/state.ts index 0377e393..f45d85e9 100644 --- a/src/types/state.ts +++ b/src/types/state.ts @@ -72,14 +72,14 @@ export interface TargetState { // TODO: Correctly type this once dependent devices are // actually properly supported dependent: { - apps: Dictionary<{ + apps: Array<{ name?: string; image?: string; commit?: string; config?: EnvVarObject; environment?: EnvVarObject; }>; - devices: Dictionary<{ + devices: Array<{ name?: string; apps?: Dictionary<{ config?: EnvVarObject; @@ -118,8 +118,8 @@ export interface InstancedAppState { releaseId: number; name: string; services: Service[]; - volumes: { [name: string]: Volume }; - networks: { [name: string]: Network }; + volumes: Dictionary; + networks: Dictionary; }; }