gpt4 book ai didi

node.js - TypeScript 中 createReadStream 的类型应该是什么?

转载 作者:行者123 更新时间:2023-12-04 14:15:36 24 4
gpt4 key购买 nike

我正在尝试使用 typescript 。应该是什么 createReadStream 的类型 ?我找到了来自 fs.d.ts 的类型声明来自此的文件 DefinitelyTypedlink github
更新
我想做的是上传文件 来自 前端 .上 后端 (基本上是 Node ),我收到了 文件对象 .在 破坏 文件对象,我得到以下信息。

const { createReadStream, filename, mimetype, encoding } = await file;
有什么办法,我可以使用这种类型吗?
更新的问题
现在,我应该如何添加 的类型文件 我收到的对象
函数参数下面给出的功能?
export const processUpload = async (file, DestinationDir) {

}
在官方 node/fs.d.ts 中找到的类型文件
function createReadStream(path: PathLike, options?: string | {
flags?: string;
encoding?: string;
fd?: number;
mode?: number;
autoClose?: boolean;
/**
* @default false
*/
emitClose?: boolean;
start?: number;
end?: number;
highWaterMark?: number;
}): ReadStream;
代码示例
export const processUpload = async (
file:
| PromiseLike<{
createReadStream: /** WHAT SHOULD BE THE TYPE */;
filename: string;
mimetype: string;
encoding: string;
}>
| {
createReadStream: /** WHAT SHOULD BE THE TYPE */;
filename: string;
mimetype: string;
encoding: string;
},

{ DestinationDir = "default" }: { DestinationDir: string }
) => {
const { createReadStream, filename, mimetype, encoding } = await file;
const stream = createReadStream();

/** SOME CODE */

return /*SOME RETURN TYPE*/
};

最佳答案

我想你可以用这个:

import { ReadStream } from "fs-capacitor";

export interface FileUpload {
createReadStream(): ReadStream;
filename: string;
mimetype: string;
encoding: string;
}

关于node.js - TypeScript 中 createReadStream 的类型应该是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60652736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com