gpt4 book ai didi

How do you setup types with Bun?(如何使用Bun设置类型?)

转载 作者:bug小助手 更新时间:2023-10-22 16:11:35 37 4
gpt4 key购买 nike



Bun is currently working on my local machine, but I cannot get it to show all of the typings in my IDE. How do I set this up to work in VS Code and other editors?

Bun目前正在我的本地机器上工作,但我无法让它显示IDE中的所有打字员。我如何设置它以在VS代码和其他编辑器中工作?


更多回答

How is this different from any other thing missing types?

这与其他缺失类型的东西有何不同?

@KevinB We've answered this question 5+ times in the discord in the past 2 days despite it being in the README. Hopefully people will search here instead of someone needing to take the effort to answer again,

Sound's like a better fit would be to have a FAQ in your discord for you to link people to.

听起来更合适的做法是在你的不和中有一个常见问题解答,让你把人们联系起来。

@KevinB I will ask if we could do that. Although, I believe stackoverflow.com/a/71244561/10873797 would be sufficient precedent to keep this open?

@KevinB我会问我们是否可以那样做。尽管如此,我相信stackoverflow.com/a/712445561/10873797将是保持这一开放的充分先例?

fwiw StackOverflow has a mechanism to make it as a "community" wiki. Just mark your answer as a "Community Wiki" one (a little checkbox at bottom left)

fwiw StackOverflow有一种将其作为“社区”wiki的机制。只需将您的答案标记为“社区Wiki”即可(左下角的一个小复选框)

优秀答案推荐

Install the bun-types NPM package:

安装bun-types NPM包:


bun add -D bun-types

Or


npm install -D bun-types

Then, create a tsconfig.json and include the package in your global types:

然后,创建一个tsconfig.json,并将包包含在全局类型中:


{
"compilerOptions": {
"types": ["bun-types"] // this is necessary
}
}

You may need to reload your editor for these types to start showing.

您可能需要重新加载这些类型的编辑器才能开始显示。


From the documentation's TypeScript guide

来自文档的TypeScript指南



nothing above works for me, i get Cannot find name 'Bun' .ts(2304) error vscode doesnt see bun types

以上任何内容都不适用于我,我得到找不到名称“Bun”。ts(2304)错误vscode看不到Bun类型


i restarted vscode, downloaded bun vscode extension, nothing.. still no types are shown.

我重新启动了vscode,下载了bun vscode扩展,什么都没有。。仍然没有显示任何类型。


i used default bun init config

我使用了默认的bun-init配置


UPD
solved by changing to this tsconfig:

通过更改为以下tsconfig解决了UPD:


{
"compilerOptions": {
// add Bun type definitions
"types": ["bun-types"],

// enable latest features
"lib": ["esnext"],
"module": "esnext",
"target": "esnext",

"moduleResolution": "bundler",
"noEmit": true,
"allowImportingTsExtensions": true,
"moduleDetection": "force",

"jsx": "react-jsx", // support JSX
"allowJs": true, // allow importing `.js` from `.ts`
"esModuleInterop": true, // allow default imports for CommonJS modules

// best practices
"strict": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true
}
}

更多回答

This can be done, but has absolutely no effect for me. Neither do I get hints in VS Code, nor does bun script.ts error if I make mistakes

这是可以做到的,但对我来说绝对没有影响。我在VS代码中也不会得到提示,如果我犯了错误,bun script.ts也不会出错

@NoBullsh1t Please try joining the Bun discord and hopefully we can better help you there.

@NoBullsh1t请尝试加入Bun的不和,希望我们能更好地帮助你。

After spending hours trying to figure out how to add Bun types to WebStorm... "reload your editor" was what I was missing! 🙏

花了几个小时试图找出如何将Bun类型添加到WebStorm。。。“重新加载你的编辑器”是我所缺少的!🙏

I would have expected this to be in the installation or quickstart on bun.sh/docs

我本以为这会出现在bun.sh/docs上的安装或快速启动中

Thanks @LiveSource , it is actually on the installation guide and I have updated the information in this answer to follow it along with the link to the section.

感谢@LiveSource,它实际上在安装指南上,我已经更新了这个答案中的信息,并附上了该部分的链接。

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com