1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Emotion] cssプロパティでエラーが出た場合の対処法

Posted at

初めに

emotionのバージョンは11です。
11から破壊的な変更が入っているので、それ以前のバージョンを使用してる人は要注意。

以下に簡単なコンポーネントサンプルを示しますが、pタグに渡しているcssプロパティの箇所で「そんなプロパティないよ」とエラーが表示されるケースがあります。

Sample.tsx
import { css } from "@emotion/react";

const Text = css({
  color: "red",
});

export const Emotion = () => {
  return (
    <Container>
      <p css={{ Text }}>Emotion</p>
      <button>Click</button>
    </Container>
  );
};

対処方法

tsconfig.jsonに以下追記する。

tsconfing.json
{
  "compilerOptions": {
    .
    .
    .   
    "jsx": "react-jsx",
    "types": ["@emotion/react/types/css-prop"], // 追記
  },
  "include": ["src"]
}

もしくは、**.d.tsを定義する

src/types/emotion.d.ts
/// <reference types="@emotion/react/types/css-prop" />

以上。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?