Search code examples
reactjstypescriptreact-intl

Typescript for defineMessages in react-intl package


The react-intl package has a defineMessages method for defining the messages for translation in the format:

const messages = defineMessages({
    'account.activation.error': {
        id: 'account.activation.error',
        defaultMessage: 'This activation link is not valid.',
    },
});

I can't find the type definitions for this package, so how would you define this using TypeScript?


Solution

  • In fact, react-intl package is shipped with it's own type definitions. So you don't have to look for external ones. You may install the package and open node_modules/react-intl/index.d.ts file in your code editor. Or use Go to definition functionality on defineMessages function if it's available in your IDE.

    playground link