3

I'm using file-loader, a webpack plugin that converts media imports as their URLs, so in import src from './image.png', src is a string.

I know I can make typescript understand that by having this in some declaration file:

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 it's very wordy, and this doesn't work:

declare module '*.{png,jpe?g,svg,gif,avif}' { export default ''; }

Is there a parameter in my tsconfig.json or a CLI option I can use so that TypeScript handles real glob patterns in declaration files?

Nino Filiu
  • 16,660
  • 11
  • 54
  • 84

1 Answers1

0

According to microsoft/TypeScript#38638, TypeScript currently does not support globs in declaration files

Improve declare module wildcards so that they can match parts of a path more like a glob

Status: opened

[...]

This is an example of what I would like to be able to do:

declare module '@my/**/icons/**/*.svg' { }
declare module '@my/**/images/**/*.svg' { }

Thanks @Aleksey L. for pointing me in this direction in the comments.

Nino Filiu
  • 16,660
  • 11
  • 54
  • 84