0

我被赋予了这项任务,以使用从带有 NodeJS 的 AirTable API 获得的数据执行一些操作。我正在使用 AirTableJS 节点库和DefinitelyTyped 空气表定义(我正在使用NestJS)。

因此,很自然地,我会执行以下操作来导入必要的包。

yarn add airtable @types/airtable

然后,在与 AirTable API 交互的存储库中,我有以下内容。

import { User } from "../entities/user";
import { ConfigService } from "@nestjs/config";
import { Inject, Injectable } from "@nestjs/common";
import { LogService } from "src/log/services/log/log.service";
import { Base } from "airtable";


@Injectable()
export class UsersRepository {
    private readonly apiKey: string;
    private readonly baseId: string;

    constructor(@Inject(ConfigService) private readonly config: ConfigService, @Inject(LogService) private readonly log: LogService) {
        this.apiKey = this.config.get<string>('airtable.apiKey');
        this.baseId = this.config.get<string>('airtable.baseId');
    }

    async getUnmatchedUsers(): Promise<User[]> {

        const base: Base = new Airtable({apiKey: this.apiKey}).base(this.baseId);
        // other code here
     }
  }

但是,在运行它时,我收到以下与存储库功能相关的错误:

ReferenceError: Airtable is not defined

我在这里遗漏了什么还是我没有正确导入 Airtable 包?

谢谢。

4

2 回答 2

1

它没有定义,因为你还没有导入Airtable.

这可能看起来像:

import Airtable, { Base } from "airtable";
于 2020-04-29T19:52:22.500 回答
0

You don't have the Airtable class imported from anywhere, so Node and Tyepscript don't have any idea what it is. The closest you have is the Base type imported from the airtable pacakge. As their documentation isn't public, it's hard to say how to fix it.

于 2020-04-29T19:52:24.300 回答