Skip to content
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

False positive Typescript cannot find module warning #104

Open
8enSmith opened this issue Aug 7, 2018 · 1 comment
Open

False positive Typescript cannot find module warning #104

8enSmith opened this issue Aug 7, 2018 · 1 comment

Comments

@8enSmith
Copy link

8enSmith commented Aug 7, 2018

I am importing an Icon using the following code:

import Icon from "!svg-react-loader?name=Icon!../images/svg/item-thumbnail.svg"

In Visual Studio Code I get the following warning from tslint:

[ts] Cannot find module '!svg-react-loader?name=Icon!../images/svg/item-thumbnail.svg'.

I still get this warning even if If I apply a tslint ignore statement:

// tslint:disable-next-line:no-implicit-dependencies

The import works fine, though I'd really like to get rid of this warning. Any ideas how to do so?

I've also posted this question on StackOverflow

@woutervanvliet
Copy link

You'll need a declaration similar to this:

declare module '*.svg' {
	import { HTMLAttributes } from 'react'
	const value: React.ComponentType<HTMLAttributes<SVGElement>>
	export default value
}

For my project, I've defined a package (using yarn workspaces) with all of my global types but that might be a bit much to do. I'm not experienced enough though to tell you exactly where to put that file.

This will only help you with the TypeScript error though. Once you've tackled that, you'll run into the tslint warning you're trying to suppress. I'll be following this thread, and your SO question for advice on that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants