Font-awesome issue with Reactjs & Typescript
See original GitHub issueI am working on React Redux and typescript app.
My package.json
contains following versions of font awesome.
"@fortawesome/fontawesome": "^1.1.8",
"@fortawesome/fontawesome-common-types": "^0.1.7",
"@fortawesome/fontawesome-free-brands": "^5.0.13",
"@fortawesome/fontawesome-free-regular": "^5.0.13",
"@fortawesome/fontawesome-free-solid": "^5.0.13",
"@fortawesome/react-fontawesome": "0.0.20",
My App.tsx
looks like this in which i am using External Loading loading method to configure fontawesome in project.
import * as React from 'react';
import { BrowserRouter, Route } from 'react-router-dom';
import Counter from './containers/Counter';
// Font awesome Stuff for Global Use
import fontawesome from '@fortawesome/fontawesome';
import brands from '@fortawesome/fontawesome-free-brands';
import regular from '@fortawesome/fontawesome-free-regular';
import solid from '@fortawesome/fontawesome-free-solid';
fontawesome.library.add(brands, regular, solid);
class App extends React.Component {
public render() {
return (
<BrowserRouter>
<div>
<p>Hello</p>
<Route path="/" component={Counter} />
</div>
</BrowserRouter>
);
}
}
export default App;
My Counter.tsx
which is in Components folder looks like this.
import * as React from 'react';
import { connect } from 'react-redux';
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
export interface IAppProps {
counter: number;
onIncrementCounter: any;
}
class Counter extends React.Component {
public props: IAppProps;
public render() {
return (
<div>
<p onClick={this.props.onIncrementCounter}>Counter: {this.props.counter}</p>
<FontAwesomeIcon icon="check-square" />
Popular gadgets come from vendors like:
<FontAwesomeIcon icon={['fab', 'apple']} />
<FontAwesomeIcon icon={['fab', 'microsoft']} />
<FontAwesomeIcon icon={['fab', 'google']} />
</div>
);
}
}
const mapStateToProps = (state: any)=>{
return {
counter: state.counter
}
}
const mapDispatchToProps = (dispatch: any)=>{
return {
onIncrementCounter: ()=> {
dispatch({type: 'INCREMENT'})
},
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Counter);
But it is giving me this issue
`Failed to compile.
/Users/cdalvi/Documents/typescript/mace-vaa-frontend/src/containers/Counter.tsx
(3,29): Could not find a declaration file for module '@fortawesome/react-fontawesome'.
'/Users/cdalvi/Documents/typescript/mace-vaa-frontend/node_modules/@fortawesome/react-fontawesome/index.js' implicitly has an 'any' type.
Try `npm install @types/fortawesome__react-fontawesome` if it exists or add a new declaration
(.d.ts) file containing `declare module 'fortawesome__react-fontawesome';`
I checked this #125 but Hard Luck 😦
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Font-Awesome Typescript error when running production ...
I am facing an issue with Font-Awesome Icons in my react project. When I run in my local its working fine but with...
Read more >Use React with... | Font Awesome Docs
You can use the Font Awesome React component with Next.js or Typescript. ... Is there another tool or framework you want to use...
Read more >How to use font awesome in React and Typescript
This article describes how to use font-awesome with a React Js project with Typescript. It's a bit different from React and Javascript ...
Read more >@types/react-fontawesome - npm
TypeScript definitions for react-fontawesome. Latest version: 1.6.5, last published: a year ago. Start using @types/react-fontawesome in ...
Read more >How to use Font Awesome icons in React - Kindacode
React + TypeScript: Handling onFocus and onBlur events. You can also check our React topic page and React Native topic page for the...
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 Free
Top 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
Hello,
I’d like to share my solution to this issue. You need to set your icon as type
IconName
,[IconPrefix, IconName]
orIconLookup
. See here. Make sure to cast your string icons (For example:const icon = 'coffee' as IconName
).Faced the same problem.
Such component doesn’t compile.
ERROR in ./src/stories/Wrapper.tsx (10,13): error TS2345: Argument of type 'IconDefinition' is not assignable to parameter of type 'IconDefinitionOrPack'. Type 'IconDefinition' is not assignable to type 'IconPack'. Index signature is missing in type 'IconDefinition'.
Why
@fortawesome/free-regular-svg-icons
and ‘@fortawesome/free-solid-svg-icons’ have different interfaces? And what should to do if I need regular icons, especially this one?