Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Messages defined inside standalone objects are not picked up. #38

Open
lukasduspiva opened this issue Dec 10, 2019 · 1 comment
Open

Comments

@lukasduspiva
Copy link

Messages which are defined using defineMessages inside standalone objects are not extracted by the parser. For example:

enum ItemStatus {
  OPENED = 'opened',
  CLOSED = 'closed',
}

const standaloneMessages: {[key in ItemStatus]: Message} = {
  [ItemStatus.OPENED]: {
    defaultMessage: 'Opened',
    id: 'app.itemStatus.Opened',
  },
  [ItemStatus.CLOSED]: {
    defaultMessage: 'Closed',
    id: 'app.itemStatus.Closed',
  },
};

const messages = defineMessages(standaloneMessages);

The problem here is that the parser will not extract the messages, but the code is still valid TypeScript, so there is no way how I can restrict the usage of this pattern. The fix in code, to get it to work is simple, but should not be both approaches supported?

// This will be extracted by parser
const messages = defineMessages<ItemStatus>({
  [ItemStatus.OPENED]: {
    defaultMessage: 'Opened',
    id: 'app.itemStatus.Opened',
  },
  [ItemStatus.CLOSED]: {
    defaultMessage: 'Closed',
    id: 'app.itemStatus.Closed',
  },
});

(using typescript-react-intl 0.4.0)

@BANG88
Copy link
Owner

BANG88 commented Dec 10, 2019

Em. This lib doesn't covered every use case. I am glad to hear that If you can dig into it and file a PR here 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants