Trung BìnhTypeScript iconTypeScript

Declaration files (.d.ts) là gì?

Declaration files chứa type declarations không có implementation (ambient declarations).

  • Dùng để type third-party libraries không viết bằng TS. @types/ packages trên npm.
  • Tự viết .d.ts khi cần declare types cho JS code hoặc global variables.
typescript
// Khai báo SVG imports (pattern phổ biến với Vite/Webpack)
declare module '*.svg' {
  const content: string;
  export default content;
}

// Mở rộng global:
declare global {
  interface Window { analytics: Analytics; }
}

Xem toàn bộ TypeScript cùng filter theo level & chủ đề con.

Mở danh sách TypeScript