简体   繁体   中英

Use typescript with react-intl

I am using in mu application react-intl . And i have the next code:

 const intl = useIntl(); const test = makeTest(error, intl.formatMessage); // call test in another file: const run = (error: ApolloError, formatMessage): string => {... };

How you can see i use typescript in my react application, but i have a problem when i want to type the formatMessage from const run = (error: ApolloError, formatMessage): string .
I searched in different sources but i could't type that parameter, how to ype formatMessage ?

The return type of useIntl can be looked up either in an IDE or from the source code https://github.com/awoodworth/react-intl/blob/master/src/components/useIntl.ts

The type ends up being

import { MessageDescriptor } from 'react-intl';

const run = (error: ApolloError, formatMessage: (descriptor: MessageDescriptor) => string): string => {
 ...
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM