Skip to content

Incorrect type for exact matches in ChoiceOptions of plural macro #2568

@tstehr

Description

@tstehr

Description

The exact match type in ChoicesOption is defined as: [digit: `${number}`]: string, which implies it should be used as follows:

const message = plural(count, {
  '0': "No Books",
  one: "# Book",
  other: "# Books",
});

However, the correct key in MessageFormat syntax is be "=0" not just "0":

const message = plural(count, {
  '=0': "No Books",
  one: "# Book",
  other: "# Books",
});

This works as expected, but leads to a type error. To fix that, the index signature in ChoicesOption should be [digit: `=${number}`]: string.

Verifications

  • I've checked the docs and this isn't covered there.
  • I've searched existing issues on GitHub.

Reproduction Steps

The following code, which works correctly, creates a type error:

const message = plural(count, {
  '=0': "No Books",
  one: "# Book",
  other: "# Books",
});

Expected Behavior

There should not be a type error.

Macro Support

SWC with @lingui/swc-plugin

Lingui Version

5.3.3

Babel Version

Framework

Vite

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions