6

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.

Chetan Jain
  • 236
  • 6
  • 16

3 Answers3

3

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.

Sarthak Agrawal
  • 321
  • 4
  • 17
1

Restart IDE worked for me, all new files got this error until restarted.

Patrik Rikama-Hinnenberg
  • 1,362
  • 1
  • 16
  • 27
0

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) => {}
Diana Vallverdu
  • 321
  • 4
  • 13