@types/styled-components Duplicate identifier FormData

I ran across this, too. Simply downgrade from the latest version of @types/styled-components. 4.0.3 (no ^) and it seems to do the trick.

(found a bunch of other people referencing similar errors in the past with @types/node which presented a similar solution).


Update 21/12/2020

Move the styled-components/native types out of @types/styled-components and into its own package (@types/styled-components-react-native). If someone wants to use styled-components/native, all they need to do is install @types/styled-components-react-native and it will automatically augment the styled-components types (since TypeScript automatically includes any installed @types packages).

This makes it so that the main export (i.e., import styled from 'styled-components') works out-of-the-box (which is the most common usage). And in order to get styled-components/native all you need to do is install the other @types package, which is still easier than having to set types: [] in tsconfig.json.

(Solution copied from the Pull request)

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/49914

Old

I had the same issue and I solved downgrading @types/styled-components to 4.1.8.

You can achieve this by: npm i @types/[email protected] --save-dev --save-exact

This issue is still open for more than 1 year, all you will find are some workarounds.

About the problem, it seems that @types/styled-components require @types/react-native and this is causing problems with DOM lib. That means if you using react for the web you're going to have conflicts because of the react-native typings with the DOM lib. If you are using React-Native, you don't need to downgrade.Try those below if you don't want to downgrade:

For NPM users a possible workaround mentioned in Github is adding:

"postinstall": "rm -rf node_modules/@types/react-native"

in your package.json to delete the types after you install them.

For yarn users you can create a .yarnclean file and add this content:

@types/react-native

as mentioned here.

You can find more information in this issue on Github.


Adding "skipLibCheck": true to compilerOptions in the tsconfig.json file solved the issue for me. The solution comes from another project created by a newer create-react-app.

Note: "skipLibCheck": true skips type checking of all declaration files ( *.d.ts ).