打字稿-无法键入样式根

问题描述

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

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上找到错误)。你能给我解释一下吗?

谢谢。

解决方法

就这么简单

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<{}>>,});

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...