代码之家  ›  专栏  ›  技术社区  ›  Miha Å uÅ¡terÅ¡ič

类型脚本类型定义-接口引用类型,但用作值

  •  0
  • Miha Å uÅ¡terÅ¡ič  · 技术社区  · 6 年前

    我有以下代码:

    export interface Chapter {
        title: string,
        path: string
    }
    
    export type TableOfContents: Chapter[]
    

    但我得到了以下错误:

    [ts]“chapter”仅指类型,但用作值 在这里。〔2693〕

    我想导出接口章节,然后导出类型tableofcontents,它是一系列章节。

    我做错什么了?

    1 回复  |  直到 6 年前
        1
  •  4
  •   Samuel Vaillant    6 年前

    要创建类型别名,必须使用 = : .

    export type TableOfContents = Chapter[]
    

    你可以看到区别 in the TypeScript playground .