I created custom_typings/image.d.ts with the following and set "typeRoots": ["./node_modules/@types", "./custom_typings"] in my tsconfig:
type ImageSource = {
blurhash: string;
views: [
{
height: number;
width: number;
url: string;
},
];
};
declare module '*.png' {
export const source: ImageSource;
}
declare module '*.jpg' {
export const source: ImageSource;
}
declare module '*.jpeg' {
export const source: ImageSource;
}
declare module '*.gif' {
export const source: ImageSource;
}
But then when I do this, it gives an error in my editor:
import { source as defaultBanner } from 'app/assets/images/default_banner.png';
// Module '"*.png"' has no exported member 'source'. Did you mean to use 'import source from "*.png"' instead? ts(2614)
What can I do to debug this? For context, I'm using Vite and trying to override their types (declared here: https://github.com/vitejs/vite/blob/main/packages/vite/client.d.ts#L57) since I've made a rollup plugin to add this export 😅
GitHub
Next generation frontend tooling. It's fast! Contribute to vitejs/vite development by creating an account on GitHub.