[英]What should be the type of createReadStream in TypeScript?
I am trying to use typescript.我正在尝试使用打字稿。 What should be the type of createReadStream ?
createReadStream的类型应该是什么? I have found the types declaration following from
fs.d.ts
file from this DefinitelyTyped link on github我从github上的这个绝对类型链接的
fs.d.ts
文件中找到了类型声明
what I am trying to do is upload a file from the frontend .我想要做的是从前端上传文件。 On backend ( basically node), I receive a file object .
在后端(基本上是节点),我收到一个文件对象。 on destructing the file object, I get the following.
在销毁文件对象时,我得到以下信息。
const { createReadStream, filename, mimetype, encoding } = await file;
Is there any way, I can use this type?有什么办法,我可以使用这种类型吗?
Now, how should I add the type of the file object that I receive in the function parameter of the function given below?现在,我应该如何在下面给出的函数的函数参数中添加我收到的文件对象的类型?
export const processUpload = async (file, DestinationDir) {
}
node/fs.d.ts
filenode/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*/
};
I think you could use this:我想你可以用这个:
import { ReadStream } from "fs-capacitor";
export interface FileUpload {
createReadStream(): ReadStream;
filename: string;
mimetype: string;
encoding: string;
}
fs.createReadStream
returns a ReadStream
object. fs.createReadStream
返回一个ReadStream
对象。 Also, the TypeScript doesn't expect you to provide a type for fs.createReadStream
.此外,TypeScript 不希望您为
fs.createReadStream
提供类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.