emilll

问一个 ts 类型提取问题

  •  
  •   emilll · Apr 15, 2021 · 2595 views
    This topic created in 1860 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   ·   5278 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 08:42 · PVG 16:42 · LAX 01:42 · JFK 04:42
    ♥ Do have faith in what you're doing.