Difference between React$ComponentType and React.ComponentType?
See original GitHub issueI’m currently experiencing an issue where replacing React$ComponentType
with React.ComponentType
in react-intl’s injectIntl() libdef fixes a type checking error.
iff --git a/flow-typed/npm/react-intl_v2.x.x.js b/flow-typed/npm/react-intl_v2.x.x.js
index 07744d6..2a78d3e 100644
--- a/flow-typed/npm/react-intl_v2.x.x.js
+++ b/flow-typed/npm/react-intl_v2.x.x.js
@@ -126,14 +126,14 @@ declare module "react-intl" {
messageDescriptors: T
): T;
declare function injectIntl<Props: {}>(
- WrappedComponent: React$ComponentType<
+ WrappedComponent: React.ComponentType<
{ intl: $npm$ReactIntl$IntlShape } & Props
>,
options?: {
intlPropName?: string,
withRef?: boolean
}
- ): React$ComponentType<Props>;
+ ): React.ComponentType<Props>;
declare function formatMessage(
messageDescriptor: $npm$ReactIntl$MessageDescriptor,
values?: Object
Although the above modification obviously does the job, and something I was about to open a PR for, I’d really appreciate understanding why that works rather than something I found out of luck by reading the React utility types 🤔
flow check error for reference
Error: src/components/more/MorePage.js:84
v----------------
84: <EnterDepositCode
85: onSubmit={submitDepositCode}
86: loading={submitDepositCodeLoading}
...:
89: />
-^ React element `EnterDepositCode`
43: export class EnterDepositCode extends React.Component<Props, State> {
^^^^^ property `intl`. Property not found in. See: src/components/more/EnterDepositCode.js:43
v----------------
84: <EnterDepositCode
85: onSubmit={submitDepositCode}
86: loading={submitDepositCodeLoading}
...:
89: />
-^ props of React element `EnterDepositCode`
Any hints?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Type Reference - JavaScript. Flow
A reference for all the utility Flow types exported by the React module. ... typeof Component . typeof Component is the component type...
Read more >React component type in TypeScript - Stack Overflow
The correct type for a functional component is React.FunctionComponent or React.FC which is a shortcut alias for it
Read more >React Top-Level API
The difference between them is that React. ... string (such as 'div' or 'span' ), a React component type (a class or a...
Read more >Documentation - JSX - TypeScript
createElement("div") ), whereas a component you've created is not ( React. createElement(MyComponent) ). The types of the attributes being passed in the JSX ......
Read more >Types of React Components. Functional, Class, Pure, and…
React components are independent and reusable code. They are the building blocks of any React application. Components serve the same purpose as JavaScript ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To use
React.ComponentType
you have to use the star import (import * as React from 'react'). If you haven't imported react that way, those types are not available off of
React. With the
$` separator, you have access to the globally defined types.Aha, thanks a lot for explaining the differences!
With your comments, I assume that flow-typed libdefs are required to use
React$ComponentType
, but application code could useReact.ComponentType
as long as the entire React namespace has been required first.