示例工程 23-esm-live-bindings

23-esm-live-bindings/04-import-type/src/main.ts

typescript · 0.4 KB

运行:23 · import-type

点击「运行示例」后,左侧显示源码、右侧显示运行结果;console 输出会实时回传。

import { area } from './types.js';
import type { Shape } from './types.js';
 
export function describe(shape: Shape, width: number, height: number): string {
  return `${shape.name}:${area(width, height)}`;
}
 
export function run(log: (msg: string) => void = console.log): string[] {
  const lines = [describe({ name: 'rect' }, 2, 3)];
  for (const line of lines) {
    log(line);
  }
  return lines;
}