简体   繁体   English

将 typescript 与 react-intl 一起使用

[英]Use typescript with react-intl

I am using in mu application react-intl .我在 mu 应用程序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 .你怎么能看到我在我的反应应用程序中使用formatMessage ,但是当我想从const run = (error: ApolloError, formatMessage): string问题。
I searched in different sources but i could't type that parameter, how to ype formatMessage ?我搜索了不同的来源,但我无法输入该参数,如何输入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 useIntl的返回类型可以在 IDE 或源代码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 => {
 ...
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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