![](/img/trans.png)
[英]TypeScript error TS5014: Unexpected token u in JSON at position 0
[英]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.