import and export
The statements that share code between modules: export makes a name available, import brings it into another file.
In more detail
import { add } from "./math.js" loads a value. When an import brings in only types, the emitter may delete it; import type makes that explicit. Import statements are resolved before any code in the file runs.
Related terms
- type-only import — An import written import type { X } or import { type X }, which brings in only types and is always removed from the output.
- module — A file of code whose functions, classes and variables other files can use by importing it.
- ECMAScript modules — The standard JavaScript module system, written with import and export statements, used by browsers and modern tools.
Taught in
- The Compiler Pipeline: tsc, AST And Code Emission — Production TypeScript
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript
- Type Annotations, Type Inference And Contextual Typing — Production TypeScript
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript
- The Spine Artifact: Generating Typed Models From OpenAPI — Production TypeScript