如何使用 Typescript 访问 yaml 映射?

How can I access yaml maps using Typescript?

我正在使用 yaml package, version 2.0.1. I know that this document should be a map, and I want to access it's property named "key". I tried doing it two different ways: both using primitive values and creating nodes myself, as described in documentation 解析 yaml 文件,但两者都会导致错误:

declare const doc: yaml.Document.Parsed;

if (yaml.isMap(doc.contents)) {

  // Argument of type 'string' is not assignable to parameter of type 'ParsedNode'
  doc.contents.get("key")

  // Argument of type 'Node' is not assignable to parameter of type 'ParsedNode'.
  doc.contents.get(doc.createNode("key"))
}

我该如何访问这张地图?

I've fixed this, so since 2.1.0 release of the package,问题中的代码现在有效,没有给出任何类型错误。