V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
emilll

问一个 ts 类型提取问题

  •  
  •   emilll · Apr 15, 2021 · 2534 views
    This topic created in 1840 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   ·   5891 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 78ms · UTC 02:47 · PVG 10:47 · LAX 19:47 · JFK 22:47
    ♥ Do have faith in what you're doing.