0Pricing
TypeScript Academy · Lesson

.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 module

All lessons in this course

  1. .d.ts basics; export type vs export
  2. Publishing packages with types
← Back to TypeScript Academy