打字稿类型定义-接口引用类型但用作值

时间:2019-01-18 12:09:11

标签: typescript

我有以下代码:

export interface Chapter {
    title: string,
    path: string
}

export type TableOfContents: Chapter[]

但是我遇到以下错误:

  

[ts]“章节”仅指类型,但被用作值   这里。 [2693]

我想导出接口Chapter,然后导出TableOfContents类型,它是各章的数组。

我在做什么错了?

1 个答案:

答案 0 :(得分:4)

要创建类型别名,您必须使用=而不是:

export type TableOfContents = Chapter[]

您可以看到区别in the TypeScript playground