Skip to content

Instantly share code, notes, and snippets.

@isimmons
Created December 19, 2022 07:00
Show Gist options
  • Save isimmons/e718f344a8c0ba5e858f2d0a6ddce10c to your computer and use it in GitHub Desktop.
Save isimmons/e718f344a8c0ba5e858f2d0a6ddce10c to your computer and use it in GitHub Desktop.
TS module declarations for css and images
// react specific css modules
declare module '*.module.css' {
const content: Record<string, string>;
export default content;
}
// react specific for direct svg import
declare module '*.svg' {
import React = require('react');
export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>;
const src: string;
export default src;
}
// these should work regardless of framework
declare module '*.jpg' {
const path: string;
export default path;
}
declare module '*.jpeg' {
const path: string;
export default path;
}
declare module '*.gif' {
const path: string;
export default path;
}
declare module '*.png' {
const path: string;
export default path;
}
declare module '*.webp' {
const path: string;
export default path;
}
@isimmons
Copy link
Author

I need to add more as I learn for React, Vue, and plain ole Typescript projects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment