簡體   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