solid-refresh
solid-refresh copied to clipboard
getForeignBindings doesn't understand enum imports
i have a tsx file roughly like:
import { ResultKind } from './kind.js'
...
resolvedCommand.kind === ResultKind.FOO
where kind.js is:
export const enum ResultKind {
FOO,
BAR,
}
the tsx gets translated to:
// no import of ResultKind in generated js
...
resolvedCommand.kind === 2 /* ResultKind.FOO */
...
location: "App.tsx:186:7",
signature: "b58d5153",
dependencies: () => ({
...
ResultKind,
setTimeout,
resulting in an error:
ERR ResultKind is not defined: ReferenceError: ResultKind is not defined
at Object.dependencies (http://localhost:5173/App.js?t=1736753306453:2814:9)
at patchComponent (http://localhost:5173/node_modules/.vite/deps/solid-refresh.js?v=81f91454:108:89)
at patchComponents (http://localhost:5173/node_modules/.vite/deps/solid-refresh.js?v=81f91454:130:9)
at patchRegistry (http://localhost:5173/node_modules/.vite/deps/solid-refresh.js?v=81f91454:167:40)
This might be a no-fix (but I'm not closing this because this is a good issue) for the following reasons:
- Since solid-refresh doesn't do cross-file analysis, there is no way for it to know that
ResultKindis aconst enum(or even justenum) - TypeScript seems to ignore this fact too, but it does raise a compiler warning.
Take note that the transformation happens before TypeScript gets to compile anything.
Currently, there is no fix for this issue (until we do cross-file analysis, but I don't see it happening any time), so I would recommend using some alternatives (either use enum, which is bad, as I am a hater of it myself or you use string unions)
Makes sense, I can work-around for now. Thanks!