typescript-react-intl is a utility library designed to extract string messages from TypeScript React components and other .ts files that leverage the React Intl library. It specifically targets messages defined using `<FormattedMessage/>` components and `defineMessages` function calls. The current stable version is 0.4.1. This package does not specify a rigid release cadence but operates with a 0.x versioning scheme, suggesting ongoing development or maintenance rather than fixed cycles. A key differentiator is its explicit support for TypeScript files and its ability to handle custom React components via a configurable `tagNames` option. It's also noted for its compatibility with React Native projects. It's important to note its limitation: it does not support `<FormattedHtmlMessage/>`.
npm install typescript-react-intlVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `typescript-react-intl` with `node-glob` and `fs` to find all TypeScript files, extract React Intl messages (including from custom components), and compile them into a locale-specific TypeScript module.
Upgrade to `typescript-react-intl@^0.3.0` and configure the `tagNames` option in the parser if you use custom components that wrap React Intl's message components.
Ensure all messages intended for extraction are defined using `<FormattedMessage/>` or `defineMessages`. Avoid `<FormattedHtmlMessage/>` if you rely on this package for message extraction.
Before calling `parse`, read the file content into a string using `fs.readFileSync(filePath, 'utf8')` or similar methods, then pass the string content to `parse`.
Pin to exact versions in `package.json` (e.g., `"typescript-react-intl": "0.4.1"`) to prevent unexpected updates. Review release notes carefully when upgrading to new minor versions.
If using CommonJS `require`, use `const parse = require('typescript-react-intl').default;`. For ESM `import`, use `import parse from 'typescript-react-intl';`.Install the package using `npm install typescript-react-intl` or `yarn add typescript-react-intl`. Ensure it's correctly listed in your `package.json` dependencies.
Pass an `Options` object to the `parse` function, including an array of strings in the `tagNames` property with the names of your custom components (e.g., `parse(contents, { tagNames: ['MyText', 'StyledMessage'] })`).No dependency data recorded yet.