@md

TypeScriptでtypeとnamespaceに同じ名前を使う

2025-04-24 12:05

#typescript

// ./lib/point.ts

export type Point = {
  x: number;
  y: number;
}

export function merge(a: Point, b: Point): Point {
  return {
    x: a.x + b.x,
    y: a.y + b.y
  };
}
// ./lib/index.ts

import * as _Point from "./point";
export * as Point from "./point";
export type Point = _Point.Point;
// index.ts

import { Point } from "./lib"

const a: Point = { x: 1, y: 2 };
const b: Point = { x: -3, y: 5 };

const c = Point.merge(a, b);
TypeScriptでtypeとnamespaceに同じ名前を使う | Maku ja aalto