Skip to content

Commit ce7c708

Browse files
committed
fix: add JSDoc Readonly type annotations for constant objects
Added proper JSDoc type annotations to VIEW_STATES, RUNTIME_STATES, and LOADING_PHASES to preserve literal type information. This ensures TypeScript recognizes the constant values as their specific literal types ('error', 'idle', etc.) rather than generic strings. Also replaced magic string 'idle' with RUNTIME_STATES.IDLE constant in errors.js RETRY transition for consistency. Fixes all type checking errors for state constant usage across transitions.
1 parent 724a0b1 commit ce7c708

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/js/types.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@
7777
/**
7878
* Constants for ViewState values
7979
* Must be synchronized with state-machine.js ViewState typedef
80+
* @type {Readonly<{
81+
* WELCOME: 'welcome',
82+
* PERMISSION: 'permission',
83+
* LOADING: 'loading',
84+
* RUNTIME: 'runtime',
85+
* ERROR: 'error',
86+
* IMAGE_UPLOAD: 'image-upload'
87+
* }>}
8088
*/
8189
export const VIEW_STATES = {
8290
WELCOME: 'welcome',
@@ -89,6 +97,14 @@ export const VIEW_STATES = {
8997

9098
/**
9199
* Constants for RuntimeState values
100+
* @type {Readonly<{
101+
* IDLE: 'idle',
102+
* WARMING: 'warming',
103+
* RUNNING: 'running',
104+
* PAUSED: 'paused',
105+
* RECOVERING: 'recovering',
106+
* FAILED: 'failed'
107+
* }>}
92108
*/
93109
export const RUNTIME_STATES = {
94110
IDLE: 'idle',
@@ -101,6 +117,12 @@ export const RUNTIME_STATES = {
101117

102118
/**
103119
* Constants for LoadingPhase values
120+
* @type {Readonly<{
121+
* LOADING_MODEL: 'loading-model',
122+
* LOADING_WGPU: 'loading-wgpu',
123+
* WARMING_UP: 'warming-up',
124+
* COMPLETE: 'complete'
125+
* }>}
104126
*/
105127
export const LOADING_PHASES = {
106128
LOADING_MODEL: 'loading-model',

src/js/utils/transitions/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const errorTransitions = [
6464
/** @this {import('../state-machine.js').default} */
6565
action: function () {
6666
this.state.error = null;
67-
this.state.runtimeState = 'idle';
67+
this.state.runtimeState = RUNTIME_STATES.IDLE;
6868
},
6969
},
7070
];

0 commit comments

Comments
 (0)