小编And*_*gon的帖子

迁移到 monorepo 结构后,Styled-jsx 打字稿错误。类型“DetailedHTMLProps”上不存在属性“jsx”

我在我的项目中使用 styled-jsx ,我只是将其迁移到 monorepo 结构,从那时起我一直遇到以下问题:

   Type '{ children: string; jsx: true; }' is not assignable to type 
   'DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>'.
   Property 'jsx' does not exist on type 
   'DetailedHTMLProps<StyleHTMLAttributes<HTMLStyleElement>, HTMLStyleElement>'.ts(2322)
Run Code Online (Sandbox Code Playgroud)

每次我使用 style-jsx 的默认标签时,它都会出现在 jsx 属性下:

    <style jsx>
        {`...`}
    </style>
Run Code Online (Sandbox Code Playgroud)

我发现了有关此主题的已关闭问题,根据此链接,如果我手动将以下两行添加到interface HTMLAttributesin中,则可以解决此问题react/index.d.ts

    jsx?: boolean;
    global?: boolean;
Run Code Online (Sandbox Code Playgroud)

这实际上解决了问题,但我不想手动修改node_modules.

根据 vercel 中的这个已关闭问题,我应该能够通过简单地运行来解决这个问题yarn add -D @types/styled-jsx,但这不起作用。

使用 npm 而不是yarn 安装包也解决了这个问题,但我不想更改我正在使用的包管理器。此外,使用 npm 安装此一个包并使用 Yarn 安装其他包会导致应用程序崩溃。

我认为这可能是与纱线工作空间相关的提升问题styled-jsx,但添加

    "private": true,
    "nohoist":["**/styled-jsx","**/styled-jsx/**"]
Run Code Online (Sandbox Code Playgroud)

到我的根 package.json …

reactjs typescript-typings monorepo styled-jsx

12
推荐指数
2
解决办法
6209
查看次数