remix icon indicating copy to clipboard operation
remix copied to clipboard

Using `as const` on an enum triggers typescript errors on `unstable_defineLoader`

Open IgnisDa opened this issue 1 year ago • 0 comments

Reproduction

https://stackblitz.com/edit/remix-run-remix-yjtvxa?file=app%2Froutes%2F_index.tsx

System Info

System:
    OS: Linux 6.9 Arch Linux
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 12.35 GB / 27.26 GB
    Container: Yes
    Shell: 5.2.26 - /bin/bash
  Binaries:
    Node: 22.1.0 - ~/.proto/bin/node
    Yarn: 4.1.1 - ~/.proto/shims/yarn
    npm: 10.7.0 - ~/.proto/shims/npm
    bun: 1.1.8 - ~/.proto/bin/bun
  npmPackages:
    typescript: 5.5.0-beta => 5.5.0-beta

Used Package Manager

yarn

Expected Behavior

There should be no typescript errors. All types being sent are serializable.

Actual Behavior

There is a typescript error:

Argument of type '({ params }: LoaderArgs) => Promise<{ metadataMapping: { readonly AUDIO_BOOK: readonly [MediaSource]; }; }>' is not assignable to parameter of type 'Loader'.
  Type 'Promise<{ metadataMapping: { readonly AUDIO_BOOK: readonly [MediaSource]; }; }>' is not assignable to type 'MaybePromise<DataFunctionReturnValue>'.
    Type 'Promise<{ metadataMapping: { readonly AUDIO_BOOK: readonly [MediaSource]; }; }>' is not assignable to type 'Promise<Serializable>'.
      Type '{ metadataMapping: { readonly AUDIO_BOOK: readonly [MediaSource]; }; }' is not assignable to type 'Serializable'.
        Type '{ metadataMapping: { readonly AUDIO_BOOK: readonly [MediaSource]; }; }' is not assignable to type '{ [key: string]: Serializable; [key: number]: Serializable; [key: symbol]: Serializable; }'.
          Property 'metadataMapping' is incompatible with index signature.
            Type '{ readonly AUDIO_BOOK: readonly [MediaSource]; }' is not assignable to type 'Serializable'.
              Type '{ readonly AUDIO_BOOK: readonly [MediaSource]; }' is not assignable to type '{ [key: string]: Serializable; [key: number]: Serializable; [key: symbol]: Serializable; }'.
                Property 'AUDIO_BOOK' is incompatible with index signature.
                  Type 'readonly [MediaSource]' is not assignable to type 'Serializable'.
                    Type 'readonly [MediaSource]' is not assignable to type '{ [key: string]: Serializable; [key: number]: Serializable; [key: symbol]: Serializable; }'.
                      Index signature for type 'string' is missing in type 'readonly [MediaSource]'.(2345)

IgnisDa avatar Jun 14 '24 13:06 IgnisDa