question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

Where are the types for @svgr/core?

See original GitHub issue

šŸ› 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:

import svgr from '@svgr/core';

Leads to this error:

<source file>:3:18 - error TS7016: Could not find a declaration file for module '@svgr/core'. '.../node_modules/@svgr/core/lib/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/svgr__core` if it exists or add a new declaration (.d.ts) file containing `declare module '@svgr/core';`

3 import svgr from '@svgr/core';
                   ~~~~~~~~~~~~

System:

  • OS: Windows 10 10.0.19042
  • CPU: (4) x64 IntelĀ® Coreā„¢ i7-6600U CPU @ 2.60GHz
  • Memory: 6.82 GB / 15.86 GB

Binaries:

  • Node: 14.15.0 - C:\Program Files\Node.js\node.EXE
  • Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
  • npm: 6.14.8 - C:\Program Files\Node.js\npm.CMD

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
jschafcommented, Apr 30, 2021

I took a stab at this. If someone cares to make it a real package, feel free.

  • I couldnā€™t figure out what the TemplateFunc type is supposed to be.
  • Iā€™m also unclear on the exported svgr function, especially the last state argument.
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;
}
2reactions
kaiyomacommented, Mar 31, 2021

Still an issue AFAIK.

Read more comments on GitHub >

github_iconTop Results From Across the Web

@svgr/core - npm
Start using @svgr/core in your project by running `npm i @svgr/core`. ... TypeScript icon, indicating that this package has built-in type ...
Read more >
How to use the @svgr/core function in @svgr/core - Snyk
To help you get started, we've selected a few @svgr/core examples, based on popular ways it is used in public projects. Secure your...
Read more >
@svgr/core | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
@svgr/core v6.5.1 Bundlephobia
Size of @svgr/core v6.5.1 is 1.2 MB (minified), and 325.3 kB when compressed using GZIP. ... These may be different from the dependencies'...
Read more >
SVGR - Transforms SVG into React Components. - SVGR
Powerful. SVGR handles all type of SVG and transforms it into a React component. Universal. SVGR is everywhere. Available online, inĀ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found