【问题标题】:Typescript - Can't type the style root打字稿 - 无法输入样式根
【发布时间】:2021-01-06 04:17:04
【问题描述】:

我认为我必须编写错误在根标记中给出的以下类型:

No overload matches this call.
  Overload 1 of 2, '(style: Styles<Theme, {}, "root">, options?: Pick<WithStylesOptions<Theme>, "flip" | "element" | "defaultTheme" | "name" | "media" | "meta" | "index" | "link" | "generateId" | "classNamePrefix">): (props?: any) => Record<...>', gave the following error.
  Type 'string' is not assignable to type 'CSSProperties | CreateCSSProperties<{}> | PropsFunc<{}, CreateCSSProperties<{}>>'

问题是我只是不知道该怎么做,以前从来没有输入过这样的东西。您可以在此处找到代码:https://codesandbox.io/s/github/pedroRelvas/HowToTypeTheStyleRoot(您可以在文件 demo.tsx 中找到错误)。请给我解释一下好吗?

谢谢。

【问题讨论】:

    标签: typescript types material-ui styles tsx


    【解决方案1】:

    就这么简单:

    const useStyles = makeStyles({
      root: `
        background: linear-gradient(45deg, #fe6b8b 30%, #ff8e53 90%);
        border-radius: 3px;
        font-size: 16px;
        border: 0;
        color: white;
        height: 48px;
        padding: 0 30px;
        box-shadow: 0 3px 5px 2px rgba(255, 105, 135, 0.3);
      ` as CSSProperties | CreateCSSProperties<{}> | PropsFunc<{}, CreateCSSProperties<{}>>,
    });
    

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 2021-02-03
      • 2021-11-11
      • 2021-12-18
      • 1970-01-01
      • 2022-08-12
      • 2021-06-07
      • 2020-06-27
      • 2018-04-26
      相关资源
      最近更新 更多