emilll

问一个 ts 类型提取问题

  •  
  •   emilll · Apr 15, 2021 · 2647 views
    This topic created in 1880 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   ·   3198 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 12:22 · PVG 20:22 · LAX 05:22 · JFK 08:22
    ♥ Do have faith in what you're doing.