There is an export import syntax for legacy modules, and a standard export format for modern ES6 modules:

// export the default export of a legacy (`export =`) module
export import MessageBase = require('./message-base');

// export the default export of a modern (`export default`) module
export { default as MessageBase } from './message-base';

// when '--isolatedModules' flag is provided it requires using 'export type'.
export type { default as MessageBase } from './message-base';

// export an interface from a legacy module
import Types = require('./message-types');
export type IMessage = Types.IMessage;

// export an interface from a modern module
export { IMessage } from './message-types';
Answer from C Snover on Stack Overflow
Top answer
1 of 3
321

There is an export import syntax for legacy modules, and a standard export format for modern ES6 modules:

// export the default export of a legacy (`export =`) module
export import MessageBase = require('./message-base');

// export the default export of a modern (`export default`) module
export { default as MessageBase } from './message-base';

// when '--isolatedModules' flag is provided it requires using 'export type'.
export type { default as MessageBase } from './message-base';

// export an interface from a legacy module
import Types = require('./message-types');
export type IMessage = Types.IMessage;

// export an interface from a modern module
export { IMessage } from './message-types';
2 of 3
90

Some more examples besides #c-snover's answer from here. You can put them together.

import 'jquery';                        // import a module without any import bindings
import $ from 'jquery';                 // import the default export of a module
import { $ } from 'jquery';             // import a named export of a module
import { $ as jQuery } from 'jquery';   // import a named export to a different name
import * as crypto from 'crypto';       // import an entire module instance object

export var x = 42;                      // export a named variable
export function foo() {};               // export a named function

export default 42;                      // export the default export
export default function foo() {};       // export the default export as a function

export { encrypt };                     // export an existing variable
export { decrypt as dec };              // export a variable as a new name
export { encrypt as en } from 'crypto'; // export an export from another module
export * from 'crypto';                 // export all exports from another module
                                        // (except the default export)
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-3-8.html
TypeScript: Documentation - TypeScript 3.8
import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there’s no remnant of it at runtime. Similarly, export type only provides an export that can be used for type contexts, and is also erased from TypeScript’s output.
Discussions

To export or not to export types (implicit vs explicit)
Types are code like any other, and globally implicitly available stuff is hard to track. You wouldn't want your foo function from one module to just be available as foo across the whole codebase, why would you want that for a Foo type? Export and import types like any other identifier. More on reddit.com
🌐 r/typescript
8
3
November 3, 2023
`export type * from 'somewhere'`
Suggestion 🔍 Search Terms typescript export type star ✅ Viability Checklist My suggestion meets these guidelines: This wouldn't be a breaking change in existing TypeScript/JavaScript code This ... More on github.com
🌐 github.com
13
April 1, 2022
How to export/import a only a type definition in TypeScript - Stack Overflow
How can I export and import a type definition independently from the module itself. More on stackoverflow.com
🌐 stackoverflow.com
Import and export TS types and interfaces in Next.js app don't needed anymore?
Summary Hello! I study Next.js and create an app based on Next.js and TypeScript. I don't add import and export to my TS interfaces and types, that are stored in another folder, and it works! C... More on github.com
🌐 github.com
2
2
June 2, 2023
🌐
TypeScript ESlint
typescript-eslint.io › blog › consistent-type-imports-and-exports-why-and-how
Consistent Type Imports and Exports: Why and How | typescript-eslint
February 24, 2023 - In conjunction with @typescript-eslint/consistent-type-imports, eslint-plugin-import's rules can enforce your imports are always properly qualified and are written in a standard, predictable style (eg always top-level type qualifier or always inline type-qualifier). TypeScript 5.0 additionally adds a new --verbatimModuleSyntax compiler option. verbatimModuleSyntax simplifies TypeScript's logic around whether to preserve imports. From the TypeScript release notes: ...any imports or exports without a type modifier are left around.
🌐
Medium
medium.com › @robinviktorsson › typescript-and-es-modules-best-practices-for-imports-and-exports-9ce200e75a88
TypeScript and ES Modules: Best Practices for Imports and Exports | by Robin Viktorsson | Medium
March 10, 2025 - Before diving into best practices, let’s review the basic ES module syntax supported by TypeScript. ... In ES modules, you can export individual elements (such as functions, variables, or classes) from a module using named exports. // math.ts export const add = (a: number, b: number): number => a + b; export const subtract = (a: number, b: number): number => a - b; You can then import these functions in other modules:
🌐
Reddit
reddit.com › r/typescript › to export or not to export types (implicit vs explicit)
r/typescript on Reddit: To export or not to export types (implicit vs explicit)
November 3, 2023 -

Hello,

I've been putting types that can be used all over my app on types.ts files. The interfaces and types in these files don't get exported and this way VSCode / Typescript somehow knows that they exist globally. This avoids having to import them whenever they are used as normally I already have quite a few other imports for actual code. That's the main reason I've been using to not having to explicitly export/import those types.

However recently I came up with two other thoughts:

  1. When creating a library, it seems the way to go is to export types. This way you can select which types are exposed (or not) and you avoid "namespacing". To avoid name conflicts when not explicitly exporting types, I normally use something like PossiblyLongNameProps or PossiblyLongNameState. These names can get long and repetitive (the PossiblyLongName part).

  2. These long names for "namespacing" got me thinking that I should probably be exporting types, at least in some cases. So it's sort of a conflict between "I don't want to be using long names for my interfaces/types" vs "I don't want to explicitly import every single type I use".

Does that make sense? What do you think? What's your approach to this?

Thank you!

🌐
TypeScript
typescriptlang.org › docs › handbook › modules.html
TypeScript: Documentation - Modules
April 11, 2023 - With TypeScript 4.5, you can use a type modifier on individual named imports. ... Each module can optionally export a default export. Default exports are marked with the keyword default; and there can only be one default export per module.
🌐
TypeScript
typescriptlang.org › docs › handbook › modules › reference.html
TypeScript: Documentation - Modules - Reference
Type aliases, interfaces, enums, and namespaces can be exported from a module with an export modifier, like any standard JavaScript declaration: ... They can also be referenced in named exports, even alongside references to standard JavaScript declarations: ... Exported types (and other TypeScript-specific declarations) can be imported with standard ECMAScript imports:
Find elsewhere
🌐
GitHub
github.com › microsoft › TypeScript › issues › 48508
`export type * from 'somewhere'` · Issue #48508 · microsoft/TypeScript
April 1, 2022 - This feature would agree with the rest of TypeScript's Design Goals. Just like export * from 'foo', we should be able to export type * from 'foo' to re-export all types (and only types).
Author   trusktr
🌐
Total TypeScript
totaltypescript.com › tips › turn-a-module-into-a-type
Turn a module into a type | Total TypeScript
So if we go to types, what we can do is we can say export type ActionModule. And we're going to use this funky little bits of TypeScript syntax. export type ActionModule = typeof import("./constants")
Published   May 30, 2023
🌐
YouTube
youtube.com › watch
⚡ ️Import & Export types the right way in TypeScript (#shortips ) - YouTube
⚡ ️Quick 2-minute tips...Importing types in TypeScript is quite a neat feature.This video explores ways to leverage TypeScript to separatetypes import/export...
Published   December 6, 2022
🌐
Educative
educative.io › answers › how-to-import-and-export-a-module-in-typescript
How to import and export a module in TypeScript
The example below shows how we import it. We use the exact name, as used in the export statement, and destructure it. ... Whenever we use export default, there are two ways in which the interfaces can be imported.
🌐
TypeScript
typescriptlang.org › docs › handbook › declaration-files › templates › module-d-ts.html
TypeScript: Documentation - Modules .d.ts
A module using CommonJS patterns uses module.exports to describe the exported values. For example, here is a module which exports a function and a numerical constant: ... The TypeScript playground can show you the .d.ts equivalent for JavaScript code.
🌐
Rip Tutorial
riptutorial.com › re-export
TypeScript Tutorial => Re-export
Typescript allow to re-export declarations. //Operator.ts interface Operator { eval(a: number, b: number): number; } export default Operator; //Add.ts import Operator from "./Operator"; export class Add implements Operator { eval(a: number, b: number): number { return a + b; } }
🌐
InfoWorld
infoworld.com › home › software development › programming languages › javascript
TypeScript 3.8 adds type-only imports and exports | InfoWorld
February 23, 2020 - The import type syntax only imports declarations to be used for type annotations and declarations and always gets fully erased. The export type syntax only provides an export to be used for type contexts and is erased from TypeScript output.
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-export-interface
How to export Interfaces and Types in TypeScript | bobbyhadz
February 28, 2024 - TypeScript uses the concept of modules, in the same way that JavaScript does. In order to be able to import a type from a different file, it has to be exported using a named or default export.
🌐
GitHub
github.com › vercel › next.js › discussions › 50684
Import and export TS types and interfaces in Next.js app don't needed anymore? · vercel/next.js · Discussion #50684
June 2, 2023 - This is an obscure TypeScript feature. If a file has no import/export, then it is not a module, so it becomes global. ... // import type {GetServerSideProps} from 'next' interface Foo { bar(): void; } type Baz = { fizz(): void; };
Author   vercel
🌐
Scaler
scaler.com › home › topics › typescript › importing and exporting with static types
Importing and Exporting with Static Types - Scaler Topics
May 4, 2023 - Any explicitly marked type import ... flag. In TypeScript, just as in EcmaScript 2015, any file that contains a top-level import and export is considered a module....
🌐
JetBrains
youtrack.jetbrains.com › issue › WEB-61664
TypeScript: Use "import type" to import types exported ...
{{ (>_<) }} This version of your browser is not supported. Try upgrading to the latest stable version. Something went seriously wrong
🌐
GitHub
github.com › microsoft › TypeScript › issues › 20273
Exporting imported types as a namespace · Issue #20273 · microsoft/TypeScript
November 26, 2017 - This question is a bit tricky and I fear I won't get an answer on StackOverflow: the question is here: https://stackoverflow.com/questions/47500855/exporting-imports-as-a-namespace-with-typescript Essentially I want to group together var...
Author   ORESoftware