-
-
Notifications
You must be signed in to change notification settings - Fork 425
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
Where are the types for @svgr/core? #513
Comments
Hey @kaiyoma 👋, |
Could we submit TS types to this repo? I'm glad to help. |
Yeah it would be great, thanks. If you do so, please add type checking to CI. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Still an issue AFAIK. |
Still an issue. |
I took a stab at this. If someone cares to make it a real package, feel free.
declare module '@svgr/core' {
export interface TemplateOptions extends SvgrOpts {
}
export interface TemplateData {
imports: string[];
interfaces: string[];
componentName: string;
props: string[];
jsx: string;
exports: string[];
}
export type TemplateFunc = ({template: unknown}, opts: TemplateOptions, data: TemplateData) => string;
export interface SvgrOpts {
/** Specify a custom config file. */
configFile?: string;
/** Replace SVG width and height with 1em to make SVG inherit text size. */
icon?: boolean;
/** Custom extension for generated files (default "js"). */
ext?: string;
/** Modify all SVG nodes with uppercase and use react-native-svg template. */
native?: boolean | {expo: boolean};
/** Generate .tsx files with TypeScript bindings. */
typescript?: boolean;
/** Keep width and height attributes from the root SVG tag. */
dimensions?: boolean;
/** Forward all properties on the React component to the SVG tag. */
expandProps?: 'start' | 'end' | false;
/** Use Prettier to format JavaScript code output. */
prettier?: boolean;
/** Specify prettier config. */
prettierConfig?: Record<string, unknown>;
/** Use SVGO to optimize SVG code before transforming into a React component. Default: true. */
svgo?: boolean;
/** Specify SVGO config. https://gist.github.com/pladaria/69321af86ce165c2c1fc1c718b098dd0 */
svgoConfig?: Record<string, unknown>;
/** Forward the ref to the root SVG tag if true. */
ref?: boolean;
/** Wrap the exported component in React.memo if true. */
memo?: boolean;
/**
* Replace an attribute value by another. Intended for changing an Icon
* color to currentColor to inherit from text color.
*
* Specify dynamic property using curly braces: { '#000': "{props.color}" }
*/
replaceAttrValues?: Record<string, string>;
/**
* Add props to the SVG tag.
*
* Specify dynamic property using curly braces: { focusable: "{true}" }.
* Particularly useful with a custom template.
*/
svgProps?: Record<string, string>
/**
* Add title tag via title property. If titleProp is set to true and no
* title is provided (title={undefined}) at render time, this will fallback
* to an existing title element in the svg if it exists.
*/
titleProp?: boolean;
/**
* Specify a template file (CLI) or a template function (API) to use.
* For an example of template, see the default one.
* https://github.com/gregberge/svgr/blob/main/packages/babel-plugin-transform-svg-component/src/index.js
*/
template?: TemplateFunc;
/** Output files into a directory. */
outDir?: string;
/**
* Specify a template function (API) to change default index.js output
* (when --out-dir is used).
*
* https://github.com/gregberge/svgr/blob/main/packages/cli/src/dirCommand.js#L39
*/
indexTemplate?: (filePaths: string[]) => string;
/** When used with --out-dir, it ignores already existing files. */
ignoreExisting?: boolean;
/**
* Specify a custom filename case. Possible values: pascal for PascalCase,
* kebab for kebab-case or camel for camelCase.
*/
filenameCase?: 'kebab' | 'camel' | 'pascal';
}
export const svgr: (svgCode: string, opts: SvgrOpts, state: TemplateData) => Promise<void>;
declare module svgr {
const sync: (svgCode: string, opts: SvgrOpts, state: TemplateData) => void;
}
export default svgr;
} |
@jschaf I added PR based on your types |
now that the library is fully in TS where can I find the Template type if i want to write my template in TS? UPD: found it svgr/packages/babel-plugin-transform-svg-component/src/types.ts Lines 4 to 11 in 1dbc3e2
|
@dreyks How are you importing this file? |
i ended up writing the template in javascript, but at some point when it was still in TS I was doing something like this import { Template } from '@svgr/babel-plugin-transform-svg-component'
const template: Template = ({ componentName, jsx }, { tpl }) => {
} |
Yep, that's the way I solved it 👍! In my case, the JS also had const iconTemplate: Template = ({ componentName, jsx }, { tpl, options }) => { |
🐛 Bug Report
Can't find the types for @svgr/core.
To Reproduce
Use @svgr/core in a TypeScript file.
Expected behavior
The types should be included with the package.
Link to repl or repo (highly encouraged)
This code:
Leads to this error:
System:
Binaries:
The text was updated successfully, but these errors were encountered: