TypeScript
Module Declarations
Write type declarations for JS libraries.
By EZ4Code Team
declarationmodule
Code
// global.d.ts
declare module "my-lib" {
export function greet(name: string): string;
export const version: string;
export interface Config {
timeout?: number;
retries?: number;
}
}
declare module "*.css" {
const content: Record<string, string>;
export default content;
}
declare module "*.png" {
const src: string;
export default src;
}
declare global {
interface Window {
myApp: { version: string };
}
}Explanation
Provides types for untyped libraries or non-JS resources via declare module.