emilll

问一个 ts 类型提取问题

  •  
  •   emilll · Apr 15, 2021 · 2621 views
    This topic created in 1870 days ago, the information mentioned may be changed or developed.
    interface Article {
      filename: string
      title: string
      date: string
    }
    
    const articles: Article[] = [
      {
        filename: 'article1',
        title: 'first article',
        date: '2021-04-13T18:10:40.578Z'
      },
      {
        filename: 'article2',
        title: 'second article',
        date: '2021-04-13T19:32:39.556Z'
      }
    ]
    
    // 从 articles 的 filename 字段提取类型
    // 结果 => type ArticleFilename = 'article1' | 'article2'
    type ArticleFilename = ???
    
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1336 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 23:51 · PVG 07:51 · LAX 16:51 · JFK 19:51
    ♥ Do have faith in what you're doing.