Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make FontAwesomeIconProps exportable #489

Closed
michaelcozzolino opened this issue Jan 7, 2024 · 11 comments
Closed

Make FontAwesomeIconProps exportable #489

michaelcozzolino opened this issue Jan 7, 2024 · 11 comments

Comments

@michaelcozzolino
Copy link

michaelcozzolino commented Jan 7, 2024

Currently in index.d.ts FontAwesomeIconProps is not exported. I cannot build a wrapper using some or all of the props. is it possible to have it exported?

@jasonlundien
Copy link
Member

jasonlundien commented Jan 7, 2024

Hi @michaelcozzolino ---

Can you give an example of what you are trying to do and/or how you would use this?

@michaelcozzolino
Copy link
Author

michaelcozzolino commented Jan 9, 2024

@jasonlundien
I have the following component and i would like to use the FontAwesomeIconProps in this way:

<template>
    <font-awesome-icon :icon="['fas', 'circle-chevron-left']" :size="size"  />
</template>

<script setup lang="ts">
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";

interface Props extends Pick<FontAwesomeIconProps, 'size'>{

}

defineProps<Props>();
</script>

@jasonlundien
Copy link
Member

@michaelcozzolino ---

Fix is in new release (3.0.6). Added you as a contribute for this as well, thanks for the headsup, patience, and support !!!

Let us know if anything else pops up.
-jason

@dmke
Copy link

dmke commented Jan 30, 2024

Hm. I've now got the following error:

srv/components/FaIcon.ts:1:15 - error TS2724: '"@fortawesome/vue-fontawesome"' has no exported member named 'FontAwesomeIconProps'. Did you mean 'FontAwesomeIcon'?

1 import type { FontAwesomeIconProps } from "@fortawesome/vue-fontawesome"
                ~~~~~~~~~~~~~~~~~~~~

With v3.0.5, this had worked. That doesn't make much sense, as you just added the exports to 3.0.6.

Maybe TypeScript implicitly exports all interfaces from .d.ts files, when there's no explicit export?

@dmke
Copy link

dmke commented Jan 30, 2024

This seems to explain it: microsoft/TypeScript#38592 (comment). @jasonlundien, would you mind adding some additional exports?

-interface FontAwesomeIconProps {
+export interface FontAwesomeIconProps {
 ...
-interface FontAwesomeLayersProps {
+export interface FontAwesomeLayersProps {
 ...
-interface FontAwesomeLayersTextProps {
+export interface FontAwesomeLayersTextProps {
 ...

@michaelcozzolino
Copy link
Author

@jasonlundien 5ce88a7#diff-7aa4473ede4abd9ec099e87fec67fd57afafaf39e05d493ab4533acc38547eb8R47
shoudlnn't the export be FontAwesomeIconProps instead of FontAwesomeIcon and so on?

@jasonlundien
Copy link
Member

Hey @dmke ---

Can you give us an example of what you are doing / how you are using it when you see the error above ?

@dmke
Copy link

dmke commented Jan 30, 2024

@jasonlundien, sure:

I've got a helper method to condense <FontAwesomeIcon :icon="['far', 'user']" /> to something like <FaRegular icon="user" />. This reduces the amount of special characters needed to get a user icon :)

The code looks like this:

FaIcon.ts
import type { FontAwesomeIconProps } from "@fortawesome/vue-fontawesome"
import type { DefineComponent } from "vue"
import { defineComponent, h, resolveComponent } from "vue"

interface CustomFAIconProps extends FontAwesomeIconProps {
  icon: string
}

export function createFaWrapper(name: string, style: string): DefineComponent<CustomFAIconProps> {
  return defineComponent({
    compatConfig: { MODE: 3 },
    name,

    // FontAwesomeIcon accepts string[] and object as well. We don't.
    props: {
      icon: { type: String, required: true },
    },

    render() {
      return h(resolveComponent("FontAwesomeIcon"), {
        icon: [style, this.icon],
      })
    },
  })
}
entrypoint.ts
import { createApp } from "vue"
import { createFaWrapper } from "./FaIcon"

const app = createApp()
app.component("FaRegular", createFaWrapper("FaRegular", "far"))
app.component("FaSolid", createFaWrapper("FaSolid", "fas"))

@Sn0wCrack
Copy link

Facing the same issue currently. Previously I was able to import everything from the index.d.ts file, however now I'm unable to import anything that is not present in the export definition.

I was able to work around this by getting the type of the props using the following TypeScript magic:

InstanceType<typeof FontAwesomeIcon>['$props']

However this is far from ideal.

@jasonlundien
Copy link
Member

This should be good now, FontAwesomeIconProps is now being exported from index.d.ts in release 3.0.8.

Let us know if anything else pops up.
Thank you,
-jason

@dmke
Copy link

dmke commented Jun 17, 2024

Can confirm, 3.0.8 exports FontAwesomeIconProps. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants