0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Solid.jsとMaterial Web Componentsを使いたいけど、型エラーが発生する

Posted at

Solid.js(TypeScript環境)でMaterial Web-Componentsを使おうとした時、型エラーが発生した。
少し詰まったので自分用メモ。

原因

Solid.jsでWebコンポーネントを使おうとした時に、Solid.jsがmaterial web componentsの型定義を見てくれず、なんじゃこのタグと言われる。

.ex)

App.tsx
import '@material/web/button/outlined-button.js';

function App {
    return (
        <md-outlined-button type="reset">Reset</md-outlined-button>
    );
}

export default App

解決法

必要に応じて、tsconfigに以下を追加

tsconfig.json
{
    "include": ["src", "src/global.d.ts"]
}

続けてsrc/global.d.tsに以下を追加

global.d.ts
import "@material/web/all"

type WithAnyChildrenAndClasses = {children:any} | {} | {class?:string, classList?:Record<string,boolean>};

type SolidInterface = {
  [P in keyof HTMLElementTagNameMap]: HTMLElementTagNameMap[P] | WithAnyChildrenAndClasses;
};

declare module "solid-js" {
  namespace JSX {
    interface IntrinsicElements extends SolidInterface { }
  }
}

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?