Utilizing the file-loader webpack plugin allows for the conversion of media imports into their URLs. For example, in import src from './image.png'
, the variable src
is treated as a string
.
To inform TypeScript about this behavior, one can create a declaration file with lines like:
declare module '*.png' { export default ''; }
declare module '*.jpg' { export default ''; }
declare module '*.jpeg' { export default ''; }
declare module '*.svg' { export default ''; }
declare module '*.gif' { export default ''; }
declare module '*.avif' { export default ''; }
However, this approach may seem verbose. Attempting to condense it using wildcards doesn't achieve the desired result:
declare module '*.{png,jpe?g,svg,gif,avif}' { export default ''; }
Is there a way to configure TypeScript through a parameter in the tsconfig.json file or a CLI option to properly handle glob patterns in declaration files?