簡體   English   中英

類型上不存在屬性“平面”

[英]Property 'flat' does not exist on type

我正在嘗試在 typescript 腳本中使用flat() 我的 tsconfig.json 中的目標設置為es2017 ,我為輸入變量定義了一個接口。 但是我確實收到錯誤Property 'flat' does not exist on type '{ type: string; source: string; target: string; }[][]' Property 'flat' does not exist on type '{ type: string; source: string; target: string; }[][]'

誰能解釋為什么會出現這個問題?

interface Dependencies {
  [key: string]: Array<{
    type: string
    source: string
    target: string
  }>
}
function example(deps: Dependencies) {
  const result = Object
    .values(deps) // Property 'flat' does not exist on type '{ type: string; source: string; target: string; }[][]'
    .flat()

  return result
}
const dependencies = {
  'foo': [
    {
      type: 'static',
      source: 'source',
      target: 'target'
    }
  ]
}
example(dependencies)

flat是在 ES2019 中添加的

ECMAScript 規范
Typescript定義

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM