.d.ts basics; export type vs export
Basics of declaration files: ambient vs module declarations, export type vs export, and ensuring correct DX for consumers.
Intro
Goal: Write useful .d.ts files. You will learn ambient vs module declarations, how to declare exports, and when to use export type vs export.
- Ambient vs module context
- Type-only vs value exports
- Good practices
Ambient declarations
Use declare global to extend the global scope. Add export {} to mark the file as a module and avoid conflicts.
// globals.d.ts
// Ambient declaration: no import/export, augments global scope
declare global {
interface Window {
APP_VERSION: string
}
}
export {} // ensures this file is a moduleAll lessons in this course
- .d.ts basics; export type vs export
- Publishing packages with types