Closed josh-m-sharpe closed 4 years ago
Unrelated, but maybe related - it might be a good idea to actually define that icon attribute as a real Type in a future refactoring. (string | number | any[])[]
has room for improvement :)
Possibly related, it seems I can't even create a IconDefinition
without throwing a type error:
import { IconDefinition } from '@fortawesome/fontawesome-common-types';
var myIconDefinition: IconDefinition = {
prefix: 'far',
iconName: 'myicon',
icon: [
512,
512,
[] as string[],
'f20a',
'M464 64H48C21.5'
]
};
[ng] ERROR in src/app/modules/ys-font-awesome-icons/ys-font-awesome-icons.module.ts:22:3 - error TS2322: Type '"myicon"' is not assignable to type 'IconName'.
[ng]
[ng] 22 iconName: 'myicon',
[ng] ~~~~~~~~
[ng]
[ng] node_modules/@fortawesome/fontawesome-common-types/index.d.ts:7:3
[ng] 7 iconName: IconName;
[ng] ~~~~~~~~
[ng] The expected type comes from property 'iconName' which is declared here on type 'IconDefinition'
I guess because IconName is already a defined list?
eh, just found this - https://github.com/FortAwesome/angular-fontawesome/issues/172 seems related.
Is there any workaround?
The example from https://github.com/FortAwesome/angular-fontawesome/issues/172#issuecomment-620873482 should work, doesn't it?
Ah - that does seem to work. Much appreciated!
Describe the problem
I'm attempting to add my own custom icon to my library using something like this: https://codepen.io/fontawesome/pen/pZWXYX
I can't seem to get around this type error:
What did you expect?
No error. Icon added to library.
Reproducible test case
Unfortunately, I can't reproduce this on stackblitz - here's a working example: https://stackblitz.com/edit/angular-z8v4ux-uxzasj. I updated angular/typescript/fortawesome packages to match what I have, but there are some others that stack blitz wouldn't install.
Below is the code from my app, which as best as I can tell is functionally the same as whats on that stackblitz case.
...and the type error I can't get around:
So, it's balking at the icon attribute:
which is basically this:
And that looks a heck of a lot like the definition: https://github.com/FortAwesome/Font-Awesome/blob/master/js-packages/%40fortawesome/fontawesome-common-types/index.d.ts#L10-L18
So, not sure why typescript is throwing an error here.