如何避免 dom / Deno 类型与 Typescript SSR 冲突
我正在尝试基于 this 使用 Typescript 和 Deno 设置 React SSR指南。基本设置有效,但是当我尝试添加 BlueprintJS 组件库时遇到了问题。
蓝图依赖于 Popper,它使用一些 DOM 类型,例如 CSSStyleDeclaration
。我的 server.tsx
需要使用 Deno
对象和 Popper(因为它需要从“components/app 导入 { App }” .tsx";
)所以理论上我需要我的 tsconfig.json 包含 Deno 和 DOM 类型,如下所示:
"lib": ["dom", "dom.iterable", "esnext", "deno.ns", "deno.unstable"],
但是这不起作用,因为它们相互冲突。但我需要它们 - 如果我删除其中一个,那么我会遇到丢失类型错误 - 无论是对于 Deno
还是对于 CSSStyleDeclaration
。
如何在不牺牲类型检查的情况下解决这个问题?
I'm trying to set up React SSR using Typescript and Deno based on this guide. The basic setup worked, however when I tried to add the BlueprintJS component library I ran into an issue.
Blueprint depends on Popper which uses some DOM types, e.g. CSSStyleDeclaration
. My server.tsx
needs to use the Deno
object and Popper (because it needs to import { App } from "components/app.tsx";
) so theoretically I need my tsconfig.json
to contain both Deno and DOM types, like this:
"lib": ["dom", "dom.iterable", "esnext", "deno.ns", "deno.unstable"],
However that doesn't work because they conflict with each other. But I need them both - if I remove either then I'll get missing type errors - either for Deno
or for CSSStyleDeclaration
.
How can I resolve this without sacrificing type checking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能,并且你需要单独对所有模块进行类型检查使用不兼容的环境类型,然后在禁用类型检查的情况下运行程序。
TypeScript 编译器(Deno 目前用来编译 TS 源文件的编译器)尚无法处理单个图中依赖于冲突环境类型的模块。
You can't, and you'll need to separately type-check all modules which use incompatible ambient types, then run your program with type-checking disabled.
The TypeScript compiler (which is what Deno currently uses to compile TS source files) isn't yet capable of handling modules in a single graph which rely on conflicting ambient types.