Skip to content

Instantly share code, notes, and snippets.

@SimeonC
Last active May 18, 2022 02:17
Show Gist options
  • Save SimeonC/d57a154937ef6eb6caecebc6f5be5808 to your computer and use it in GitHub Desktop.
Save SimeonC/d57a154937ef6eb6caecebc6f5be5808 to your computer and use it in GitHub Desktop.
A script to generate typescript types for @carbon/icons-react v11
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