简体   繁体   English

当我想使用文件缓冲区调用函数时,我必须使用哪种打字稿类型?

[英]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.

相关问题 调用 async function 时是否必须添加等待? - Do I have to add await when I call async function? 如何在 Typescript 中指定我想要的重载函数? - How to specify which overloaded function I want in Typescript? Typescript - Function 返回类型如果我想返回 object - Typescript - Function return type if I want to return object 如果我想使用 node.js (mongodb)、邮递员和颤振连接后端,我必须使用哪个 Url? - Which Url do I have to use if I want to connect a back-end using node.js (mongodb), postman and flutter? 我想在项目中使用twilio api,但是当我在打字稿文件中导入twilio时出现错误 - I want to use twilio api in my project but when I am importing the twilio in my typescript file it gives an error 在 function 调用期间,如何在 Typescript 中使用 rest 参数? - During a function call how can I use rest parameters in Typescript? 我在快速打字稿中使用什么类型的应用程序 - what type do I use for app in express typescript 为函数定义接口,我无权访问声明 - Define Interface for function, for which I do not have access to the declaration 我有一个带有链承诺的函数,此后我想返回一个整数值,但是在函数解析之前我不确定 - I have a function with chained promises after which I want to return an integer value but I get undefined before function is resolved 当我想使用Ember.js时应该选择哪个版本? - Which version should I choose when I want to use Ember.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM