Last active
May 18, 2022 02:17
-
-
Save SimeonC/d57a154937ef6eb6caecebc6f5be5808 to your computer and use it in GitHub Desktop.
A script to generate typescript types for @carbon/icons-react v11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs'; | |
import path from 'path'; | |
import carbonIcons from '@carbon/icons-react'; | |
const fileContent = `${Object.keys(carbonIcons).reduce( | |
(result, iconName) => | |
`${result} declare export const ${iconName}: ComponentType;\n`, | |
`/* this file is generated, recommend adding to prettier and eslint ignore and committing to git. DO NOT EDIT */ | |
declare module '@carbon/icons-react' { | |
type SizeType = 16 | 20 | 24 | 32; | |
type ComponentType = React.ForwardRefExoticComponent< | |
{ | |
size: SizeType | \`\${SizeType}\`; | |
} & React.RefAttributes<SVGSVGElement> | |
>; | |
` | |
)}\n}`; | |
fs.writeFileSync( | |
path.resolve('./src/definitions/carbonIcons.d.ts'), | |
fileContent | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment