Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use query param import in webpack with typescript without getting Cannot find module?


import a from 'a.png?sizes[]=64'

but I get a ts error Cannot find module 'a.png?sizes[]=64'. All works with webpack, but tsc check types fails because there is no file like that. That should only check for a.png with query param.

Any ideas how to do that? I run this command to check types tsc --project ./tsconfig.json --noEmit

One hack is to use require() syntax but that will skip any checks. So even if the file is missing, no error will happen.

like image 855
07mm8 Avatar asked Mar 23 '20 15:03

07mm8


1 Answers

Adding additional declaration helped, but there must be a better way.

e.g. types/import-png.d.ts

declare module '*.png' {
  const value: string;

  export default value;
}

declare module '*.png?inline' {
  const value: string;

  export default value;
}
like image 136
igor Avatar answered Jun 11 '23 15:06

igor