TypeScript:允许对象上具有特定值类型的任何键,该对象具有一些具有不同值类型的键

时间:2021-05-07 18:19:27

标签: typescript types record

我有两种const spawnMeteorP = () => { setInterval(() => { let x, y; if (Math.random() < 0.5) { x = Math.random() < 0.5 ? -50 : cvs.width + 50; y = Math.random() * cvs.height; } else { x = Math.random() * cvs.width; y = Math.random() < .5 ? -50 : cvs.height + 50 } const angle = Math.atan2(rocketY - y, rocketX - x); const velocity = { x: Math.cos(angle), y: Math.sin(angle) } meteors.push(new MeteorP(x, y, velocity)) }, 1500) }

  • Frontmatter,这是一个带有 FrontmatterTaxonomykind: "taxonomy" 的对象,taxnomyName
  • string,这是一个带有 FrontmatterContent 的对象,它也应该允许任何其他键,只要它们的值是 kind: "content"

我不确定如何对此建模 - 到目前为止,我尝试了相当简单的方法,但这不起作用,因为 string[] 不是 "content" 类型。

我怎样才能做到这一点?

"TaxonomyTerms"

0 个答案:

没有答案
相关问题