首页 > 解决方案 > TypeScript:如何在 basic-ftp NodeJS 模块中引用 internal.Writable?

问题描述

basic-ftp 模块 API 文档中,我读到:

downloadTo(writableStream | localPath, remotePath, startAt = 0): Promise<FTPResponse>

但是当我将模块链接到 TypeScript 项目时,我读到:

(method) Client.downloadTo(destination: string | internal.Writable, fromRemotePath: string, startAt?: number | undefined): Promise<bf.FTPResponse>

因此,虽然我WritableStream在 TypeScript 中有输入(@types/node至少有),但我没有(出于明显的原因)该internal.Writable类型。

我试图将其包装在“帮助器”方法中(只是为了简化我的特定应用程序中的任务),如下所示:

function get(file: string, contents : WritableStream) : boolean {
  if (!connected()) {
    log_err("Attempt to get() without an active FTP connection.");
  }
  ftp_client.downloadTo(contents, file);
}

然后打电话给downloadTo()我从 IntelliSense 收到消息:

Argument of type 'WritableStream<any>' is not assignable to parameter of type 'string | Writable'.

我在这里想念什么?虽然我希望不能仅仅从WritableStreamto中“隐式转换” internal.Writable,但我不确定该指向哪里。

我正在使用的一些版本:

╔═════════════╦═════════╗
║    Software ║ Version ║
╠═════════════╬═════════╣
║         TSC ║ 3.8.3   ║
║      NodeJS ║ 12.16.2 ║
║         NPM ║ 6.14.4  ║
║ @types/node ║ 13.11.1 ║
║   basic-ftp ║ 4.5.4   ║
║  Windows 10 ║ 1903    ║
║      VSCode ║ 1.44.2  ║
╚═════════════╩═════════╝

标签: javascriptnode.jstypescripttypes

解决方案


好的,我错过了:

import { Writable } from "stream";

通过检查 basic-ftp 的src/Client.ts 文件(或只是本地文件Client.d.ts)发现了这一点。


推荐阅读