Ts支持和JS一样的导出语法 主要是 ES模块

    1. // @filename: animal.ts
    2. export type Cat = { breed: string; yearOfBirth: number };
    3. export interface Dog {
    4. breeds: string[];
    5. yearOfBirth: number;
    6. }
    7. // @filename: app.ts
    8. import { Cat, Dog } from "./animal.js";
    9. type Animals = Cat | Dog
    1. // @filename: animal.ts
    2. export type Cat = { breed: string; yearOfBirth: number };
    3. // 'createCatName' cannot be used as a value because it was imported using 'import type'.
    4. export type Dog = { breeds: string[]; yearOfBirth: number };
    5. export const createCatName = () => "fluffy";
    6. // @filename: valid.ts
    7. import type { Cat, Dog } from "./animal.js";
    8. export type Animals = Cat | Dog;
    9. // @filename: app.ts
    10. import type { createCatName } from "./animal.js";
    11. const name = createCatName();
    1. // @filename: app.ts
    2. import { createCatName, type Cat, type Dog } from "./animal.js";
    3. export type Animals = Cat | Dog;
    4. const name = createCatName();