【问题标题】:Defining a typescript object and specifying optional element定义打字稿对象并指定可选元素
【发布时间】:2016-06-22 11:37:23
【问题描述】:

我有一个类型脚本类,它有这样的属性

pages: Array<{title: string, component: any, icon: any}>

我怎样才能使数组的icon 部分成为可选的?这样这将是一个有效的值

this.pages = [
        { title: 'Dashboard', component: Page1, icon: 'clipboard' },
        { title: 'Page dos', component: Page2 },
        { title: 'Page dos', component: Page2 }
];

我对打字稿很陌生

【问题讨论】:

    标签: javascript arrays typescript


    【解决方案1】:

    可选属性可以使用问号:

    pages: Array<{title: string, component: any, icon?: any}>
    

    【讨论】:

      猜你喜欢
      • 2019-07-30
      • 1970-01-01
      • 2019-12-24
      • 2019-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-19
      • 2020-12-24
      相关资源
      最近更新 更多