小编Bli*_*ers的帖子

在新的 @material-ui/core 中使用 withStyles 和 Typescript

我正在尝试更新我的一些旧打字稿,这些打字稿在新的 @material-ui/core 旁边使用了 material-ui@。

Typescript Version: 2.8.3
@material-ui/core: 1.1.0
Run Code Online (Sandbox Code Playgroud)

我已经实现了一个非常简单的组件,它只需要一个 prop,但是 typescript 编译器在使用时会抛出以下错误

src/App.tsx(21,26): error TS2322: Type '{ classes: true; imageUrl: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Placeholder> & Readonly<{ children?: ReactNode; }>...'.
  Type '{ classes: true; imageUrl: string; }' is not assignable to type 'Readonly<PROPS_WITH_STYLES>'.
    Types of property 'classes' are incompatible.
      Type 'true' is not assignable to type 'Record<"root", string>'.
Run Code Online (Sandbox Code Playgroud)

这是组件 Placeholder.tsx

import * as React from "react";
import { StyleRulesCallback, WithStyles, withStyles, StyledComponentProps } from …
Run Code Online (Sandbox Code Playgroud)

typescript reactjs material-ui

6
推荐指数
1
解决办法
6267
查看次数

标签 统计

material-ui ×1

reactjs ×1

typescript ×1