Modules

suggest change

Use standard ECMAScript export and import syntax. Prefer named exports because they are easy to discover and refactor.

export interface User {
  id: string;
  name: string;
}

export function displayName(user: User): string {
  return user.name;
}

In another file, import runtime values normally and mark type-only imports with type. With verbatimModuleSyntax, that modifier is required and makes erasure explicit:

import { displayName, type User } from "./users.js";

const user: User = { id: "1", name: "Ada" };
console.log(displayName(user));

With Node-style ESM and moduleResolution: "NodeNext", relative import specifiers use the emitted .js extension even in .ts source files. That mode follows the nearest package.json: without "type": "module" (and without an .mts extension), the file is CommonJS, and verbatimModuleSyntax then rejects a top-level value export. Bundler resolution commonly permits extensionless relative imports. Let the project's module and moduleResolution settings model the actual runtime or bundler.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents