Reputation: 241
Version "typescript": "^3.9.5" "@types/react": "^16.9.36", Property 'FC' does not exist on type 'typeof React I'm all out of ideas.
In .tsx files that contain react, I am continually getting the errors:
Property 'FC' does not exist on type 'typeof React'.
and
I get this in every .tsx file that contains react.
I know it has to be some combination of my Visual Studio configuration and the project config.
Anyone have any ideas for what to check that would only affect some workstations? I can provide as much as I can without giving away company info.
Upvotes: 9
Views: 10795
Reputation: 12181
In my case, I accidentally wrote
class Square: React.FC<ISquare> = ({}) => {
return (<></>)
}
instead of
const Square: React.FC<ISquare> = ({}) => {
return (<></>)
}
Upvotes: 0
Reputation: 381
In case it's useful for anyone, this error message came up for me when I misspelled my component definition with an =
sign instead of :
.
So, I had written:
const My Component = React.FC<Iprops> = (props) => {}
instead of:
const My Component : React.FC<Iprops> = (props) => {}
Upvotes: 3
Reputation: 1600
Restart IDE worked for me, all new files got this error until restarted.
Upvotes: 1
Reputation: 586
Encountered this problem due to syntax error on my end. If you are migrating from React native to the typescript one, check whether you converted the following properly:
function Counter(props: {initialCount: string}) {
...
}
to
interface CounterProps {
initialCount: string
}
const Counter : React.FC<CounterProps> = (props: CounterProps) => {
...
}
If this does not solve the problem then check whether the React that is getting imported, from where is it getting imported?
FC can be found in @types/react in node_modules/@types/react/index.d.ts/React
.
Upvotes: 4