给出以下代码:
import * as fs from 'fs';
import {promises as fsPromises} from 'fs';
// ...
// Read the file with no encoding for raw buffer access.
const { bytesRead, buffer as fileBuffer } = await fsPromises.read(fileDescriptor, allocBuffer, 0, bytes.length, 0);
我的打字稿短绒失败,并显示:Property 'filebuffer' does not exist on type '{ bytesRead: number; buffer: Buffer; }
我不喜欢简单的buffer
名称;有什么办法可以像这样通过await
导入更改导出?
是添加附加行的唯一方法:let fileBuffer = buffer
?
答案 0 :(得分:4)
您应该这样使用:
而不是as
:
const { bytesRead, buffer: fileBuffer } = await fsPromises.read(handle, allocBuffer, 0, bytes.length, 0);