vue-fontawesome icon indicating copy to clipboard operation
vue-fontawesome copied to clipboard

how to use it in vue project with Typescript ?

Open Hellowor1d opened this issue 6 years ago • 16 comments

error just like that : TS7016: Could not find a declaration file for module '@fortawesome/vue-fontawesome'. '/../Workspace/../node_modules/@fo rtawesome/vue-fontawesome/index.js' implicitly has an 'any' type.


Having seen the issue"Added typescript definitions" in your another repo, named react-fontawesome, knew that you are hard working on typescript definitions. I felt little ashamed, too poor knowledge about typescript definitions to solve this issue .

Thank you~

Hellowor1d avatar Dec 18 '17 12:12 Hellowor1d

Until the definitions are available, you can include this in your Typescript globals file:

declare module '@fortawesome/*';

skegel13 avatar Dec 20 '17 02:12 skegel13

We're actively working on the Typescript defs and should have something out soon.

robmadole avatar Jan 05 '18 18:01 robmadole

By Typescript globals file do you mean vue.d.ts in the node_modules directory or tsconfig.json? Just learning so sorry for such a 101 question.

lee-alderdice avatar Jan 24 '18 11:01 lee-alderdice

@skegel13 same problem here, where do I have to put that code? @lee-alderdice did you use it?

ThePlastic avatar Feb 06 '18 18:02 ThePlastic

@ThePlastic I put declare module '@fortawesome/*'; in my globals.d.ts file located in the root of my typescript code.

skegel13 avatar Feb 06 '18 19:02 skegel13

@skegel13 u saved my day, I needed a fast workaround.. Tnx a lot

Looking forward typescript integration

ThePlastic avatar Feb 06 '18 20:02 ThePlastic

Thank you @skegel13, my production build was failing because of these missing types

dannyk08 avatar Apr 29 '18 17:04 dannyk08

@robmadole did you ever get these defs done?

https://github.com/FortAwesome/vue-fontawesome/issues/24#issuecomment-355632502

VictorioBerra avatar Jun 25 '18 00:06 VictorioBerra

You add the new global file to include arrray.

VictorioBerra avatar Jun 27 '18 13:06 VictorioBerra

@ThePlastic I have just sorted this today, did post a comment that @VictorioBerra replied to above about adding it to tsconfig but a lightbulb went off (at last). Added a type.d.ts file with one line it declare module '@fortawesome/*';

Now I can do the same for vue-chartjs! -- progress!

lee-alderdice avatar Jun 27 '18 13:06 lee-alderdice

Does the charts thing require fontawesome? Or does it also not have typings?

On Wed, Jun 27, 2018, 8:25 AM K7Buoy [email protected] wrote:

@ThePlastic https://github.com/ThePlastic I have just sorted this today, did post a comment that @VictorioBerra https://github.com/VictorioBerra replied to above about adding it to tsconfig but a lightbulb went off (at last). Added a type.d.ts file with one line it declare module '@fortawesome/*';

Now I can use vue-chartjs https://github.com/apertureless/vue-chartjs! :-)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FortAwesome/vue-fontawesome/issues/24#issuecomment-400670084, or mute the thread https://github.com/notifications/unsubscribe-auth/ACzG6zvw1Ds6j6lJDEs3znLnONBpacGaks5uA4fDgaJpZM4RFbdL .

VictorioBerra avatar Jun 27 '18 13:06 VictorioBerra

It doesn't have typings. They are currently on a pull-request.


From: "Victorio Berra" [email protected] Sent: 27 June 2018 14:28 To: "FortAwesome/vue-fontawesome" [email protected] Cc: "K7Buoy" [email protected], "Mention" [email protected] Subject: Re: [FortAwesome/vue-fontawesome] how to use it in vue project withTypescript ? (#24)
Does the charts thing require fontawesome? Or does it also not have typings?

On Wed, Jun 27, 2018, 8:25 AM K7Buoy [email protected] wrote:

@ThePlastic https://github.com/ThePlastic I have just sorted this today, did post a comment that @VictorioBerra https://github.com/VictorioBerra replied to above about adding it to tsconfig but a lightbulb went off (at last). Added a type.d.ts file with one line it declare module '@fortawesome/*';

Now I can use vue-chartjs https://github.com/apertureless/vue-chartjs! :-)

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/FortAwesome/vue-fontawesome/issues/24#issuecomment-400670084, or mute the thread https://github.com/notifications/unsubscribe-auth/ACzG6zvw1Ds6j6lJDEs3znLnONBpacGaks5uA4fDgaJpZM4RFbdL .

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

lee-alderdice avatar Jun 27 '18 13:06 lee-alderdice

Hi, I'm using typescript version 3.0.0, without types. I had to create a new file inside @fortawesome/vue-fontawesome named index.d.ts with this inside:

file: index.d.ts declare module '@fortawesome/vue-fontawesome';

and inserted in the package.json in @fortawesome/vue-fontawesome this field:

file: package.json "types": "index.d.ts",

after, I had to import in my component.vue file

file: SampleComponent.vue

import { library } from '@fortawesome/fontawesome-svg-core'
import { faCoffee } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
library.add(faCoffee)

@Component({
   name: SampleComponent,
   components: {
        FontAwesomeIcon,
    },
})

and use in my html

<font-awesome-icon icon="coffee"></font-awesome-icon>

I hope it help's someone!

antoniorib91 avatar Aug 20 '18 14:08 antoniorib91

Try to use require instead. Like that:

/* tslint:disable:no-var-requires */
const fontawesome = require('@fortawesome/vue-fontawesome');

And then set the component like that:

Vue.component('font-awesome-icon', fontawesome.FontAwesomeIcon);

Works fine with:

  • Typescript 3.0.3
  • tslint 5.11.0
  • vue-fontawesome 0.1.1
  • Vue 3.0.1

pheliperocha avatar Sep 02 '18 01:09 pheliperocha

There's currently type definitions shipped with vue-fontawesome, but they don't work with TSX.

luxalpa avatar Oct 07 '19 20:10 luxalpa

We don’t use TS so any PRs that can fix it for you we will most likely merge.

robmadole avatar Oct 08 '19 22:10 robmadole

Closing this issue. Both our Vue 2 and Vue 3 components support TS with our Docs show how to import and add icons.

jasonlundien avatar Nov 03 '22 19:11 jasonlundien

I'm still not getting error on invalid values or autocomplete for its props in my template while editing:

<fa :icon="['asdasdasd', 'asdasd']"></fa>

Am I missing something?

nelson6e65 avatar Mar 20 '23 22:03 nelson6e65

Never mind, I find out by adding into global components:

// types/vue-core.d.ts

// ...
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';

declare module 'vue' {
  // ..
  interface GlobalComponents {
    fa: typeof FontAwesomeIcon;
  }
}

Inspiration: https://stackoverflow.com/a/70223296/7242535


Shouldn't be this in a FAQ or somewhere?

nelson6e65 avatar Mar 20 '23 22:03 nelson6e65

@nelson6e65 ---

I am not fully understanding... what are you thinking should be in a FAQ ?

jasonlundien avatar Mar 20 '23 22:03 jasonlundien

@jasonlundien The installation of typescript typing for the Vue 3's global component (types/vue-core.d.ts in my example, <fa/>).

nelson6e65 avatar Mar 20 '23 22:03 nelson6e65