Skip to content

Changing behavior for map key: The type of key must be string or number #255

Description

@PejmanNik

The repository has a limitation where it throws an error: "The type of key must be string or number"

I’d like to understand whether it’s acceptable to address this by converting the key to JSON before processing or by adding a callback function for the consumer to handle this case.

Using an object as a key is supported in other languages, and I need to decode data encoded with a MessagePack library from another language.

Activity

  1. gfx commented on Feb 5, 2025

    @gfx
    Member

    I know MessagePack spec allows any types to be used as keys, but it doesn't make sense to JavaScript's object. Map can have any type of keys, but easiest solution is not to use non-string objects as keys.

  2. PejmanNik commented on Feb 5, 2025

    @PejmanNik
    Author

    ok, so it won't fix but are you open to a PR for adding a callback to handle this case with the option object? or extending the key decoder for this?

  3. gfx commented on Feb 6, 2025

    @gfx
    Member

    are you open to a PR for adding a callback to handle this case with the option object? or extending the key decoder for this?

    Yes, I think callbacks may be better. But be careful, performance is important. I might reject any PRs that affect performance.

  4. added a commit that references this issue on Feb 19, 2025
    59057ee
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

    wontfixIt won't be fixed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions