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

Always verify import path #40450

Open
tiagoporto opened this issue Sep 9, 2020 · 2 comments
Open

Always verify import path #40450

tiagoporto opened this issue Sep 9, 2020 · 2 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@tiagoporto
Copy link

tiagoporto commented Sep 9, 2020

In many projects is necessary work with files which isn't a TS/JS file. Some common ones are png, jpg, svg, but when importing this files we get Cannot find module or its corresponding type declarations. error.

Searching how to fix that, we come across many discussions suggesting using the global module declaration, such as:

declare module '*.svg' {
  const content: string
  export default content
}

Links

This approach fix the lint error, but disable TS intellisense.

Example

Folder structure

app
 |
 ├ img
 |  └─ top-view.svg
 |
 └─index.ts

index.ts
68747470733a2f2f692e737461636b2e696d6775722e636f6d2f6d36494a592e706e67

No errors, but the correct path is ../img/top-view.svg

Here is the related issue #40333


Suggestion

Compiler could still returning missing type declarations for not TS/JS files. But always check if import path results in a file and return an error if not (even if file is not an TS/JS).

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Sep 9, 2020
@shaianest
Copy link

dude its not working as intended the intended way is as if you suggest some thing else or always verify import paths
if you know any way else for module augmentation or any thing els please help others

example fix might look like "you could inerface it so it can validate path and know what its return looks like
example interface "*.svg"{
ReactComponent: JSX.Element
}

"

@aaronadamsCA
Copy link

I just noticed this behaviour too. It's a shame - I was hoping to disable ESLint checking import paths, since TypeScript is already doing this for us. But it doesn't notice missing non-JS/TS assets, which is a problem.

Any reason this is tagged "Awaiting More Feedback"? I'm not sure what the documented behaviour was for module augmentations, but I'm pretty sure TS should still be attempting module resolution in spite of the module declaration, shouldn't it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants