Skip to content

getForeignBindings doesn't understand enum imports #74

Open

Description

@tmm1

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)

Activity

  1. lxsmnsyc commented on Jan 13, 2025

    @lxsmnsyc
    Member

    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 ResultKind is a const enum (or even just enum)
    • 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)

  2. tmm1 commented on Jan 13, 2025

    @tmm1
    Author

    Makes sense, I can work-around for now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions