![](/img/trans.png)
[英]What is the difference between "createReadStream" and "Readable" class?
[英]What should be the type of createReadStream in TypeScript?
我正在嘗試使用打字稿。 createReadStream的類型應該是什么? 我從github上的這個絕對類型鏈接的fs.d.ts
文件中找到了類型聲明
我想要做的是從前端上傳文件。 在后端(基本上是節點),我收到一個文件對象。 在銷毀文件對象時,我得到以下信息。
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;
}
fs.createReadStream
返回一個ReadStream
對象。 此外,TypeScript 不希望您為fs.createReadStream
提供類型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.