繁体   English   中英

从 ts 文件导出多个 typescript 类型别名时出现“意外令牌”错误

[英]Error “ Unexpected token” when export multiple typescript type alias from a ts file

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

错误将出现在export type {

type abc = {
  a: string;
};

type bbc = {bbb: string}

export type {
  abc,
  bbc,
}

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

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

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

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

export type abc = {
  a: string;
};

export type bbc = {bbb: string}

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

我认为您唯一的问题是将关键字type添加到您的导出中:

type abc = {
  a: string;
};

type bbc = {bbb: string}

export { abc, bbc }

这对你有用还是你仍然得到同样的错误?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM