TypeScript · Senior · Question 50 of 75

What is declare module '*.svg' used for?

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

Explanation

Wildcard module declarations describe what importing bundler-handled files returns (images, CSS Modules, ?raw). Frameworks usually ship such declarations themselves (next-env.d.ts, vite/client).

Further reading

Problem with a question

TypeScript · Senior · question 50

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz