[英]Which typescript type do I have to use when I want to call a function with file buffer?
I want read an image in filebuffer, change this in a function and than write back.我想读取文件缓冲区中的图像,在函数中更改它,然后写回。
In Javascript:在 JavaScript 中:
const changeImage = ( buf) => {
... change buf
return buf
}
let imageFileBuffer = fs.readFileSync('./in.png');
let newBuf = changeImage(imageFileBuffer)
fs.writeFileSync('out.png', newBuf);
How do i convert this to typescript?我如何将其转换为打字稿? What is the type of buf?
buf的类型是什么?
If you run npm install -D @types/node
, you will have node types available.如果您运行
npm install -D @types/node
,您将拥有可用的节点类型。 After doing this, reload your window (close VS Code, or do CTRL + SHIFT + P and select reload [CMD + SHIFT + P on mac]).执行此操作后,重新加载您的窗口(关闭 VS Code,或执行 CTRL + SHIFT + P 并选择重新加载 [CMD + SHIFT + P 在 mac])。
Now hover over your imageFileBuffer
variable to see what type it is (should just be Buffer).现在将鼠标悬停在
imageFileBuffer
变量上以查看它是什么类型(应该只是 Buffer)。 Then add the type to your variable to get the intellisense to do the import of the type.然后将类型添加到您的变量中以获得智能感知来执行类型的导入。
EDIT编辑
I just checked one of my projects and there is nothing to import after installing the types package.我刚刚检查了我的一个项目,安装类型包后没有任何东西可以导入。 They are defined as global.
它们被定义为全局的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.