首页 > 解决方案 > 新图像/新表/新按钮错误 Typescript 编译

问题描述

我正在创建一个 Google 操作,但我遇到new了某些元素的关键字问题。例如这里:

conv.ask(new Table({
  title: ``,
  subtitle: '',
  image: new Image({
    url: '',
    alt: 'Logo'
  }),
  columns: [
    {
      header: 'Line',
      align: 'CENTER',
    },
    {
      header: 'Destination',
      align: 'LEADING',
    },
    {
      header: 'Car',
      align: 'TRAILING',
    },
    {
      header: 'Arrival',
      align: 'TRAILING',
    },
  ],
  rows: timetableCells,
  buttons: new Button({
    title: 'Button Title',
    url: 'https://github.com/actions-on-google'
  }),
}))

引用了任何地方new我最终在编译时出现错误:

src/index.ts(21,20):错误 TS2304:找不到名称“表”。

src/index.ts(24,20):错误 TS2304:找不到名称“图像”。

src/index.ts(47,22):错误 TS2304:找不到名称“按钮”。

这是我的 tsconfig:

{
  "compilerOptions": {
    "lib": ["es6"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "target": "es6"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

我理解为什么会抛出这个错误,但我不确定这些来自 Google示例中的哪个库。

标签: typescriptactions-on-google

解决方案


哎呀,这比我想象的要明显得多。把这个留在这里,以防它帮助其他人。

import {dialogflow, Image, Table, Button} from 'actions-on-google';

推荐阅读