Modules
A module is a file that shares some code and keeps the rest private.
You export what others may use.
You import what you need from other files.
TypeScript understands both values and types across modules.
export and import
Export means make a name available to other files.
Import means bring that name into this file.
Named exports use curly braces.
default exports
A file can have one default export.
Importers can pick any local name for it.
Named exports are often clearer in big projects.
export type
Use export type when you share only a type.
Types disappear at runtime.
This makes that intent clear to tools and people.
Re-exports
A barrel file can gather exports from many modules.
Re-export means export something you imported.
Keep barrels small so they stay easy to follow.
Modules vs scripts
A file with import or export is a module.
Top level names stay private to that file.
That avoids accidental name clashes across the project.
A clash means two things with the same name fighting.
Export only what others need. Import only what you use. Keep files small and clear.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.