BANG88/typescript-react-intl

Messages defined inside standalone objects are not picked up.

Opened this issue · 1 comments

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)

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 😄