首页 > 解决方案 > 从 ts 文件导出多个 typescript 类型别名时出现错误“Unexpected token”

问题描述

沙盒:https ://codesandbox.io/s/typescript-export-question-tlbd2

错误将开启export type {

type abc = {
  a: string;
};

type bbc = {bbb: string}

export type {
  abc,
  bbc,
}

导出类型是不应该做的吗?我正在尝试尽可能多地重用类型。如果有更好的选择请告诉我

标签: javascripttypescript

解决方案


如果您尝试导出类型以便可以像这样导入它们:

import { abc, bbc } from './my-types';

您可以在声明它们时简单地导出:

export type abc = {
  a: string;
};

export type bbc = {bbb: string}

但您可能也在寻找 TypeScript namespace,如果是这种情况,请查看此处的文档


推荐阅读