メインコンテンツまでスキップ
バージョン: v4.42

型付きコンポーネント

Web Components generated with Stencil come with type declaration files automatically generated by the Stencil compiler.

In general, TypeScript declarations provide strong guarantees when consuming components:

  • 適切な値がプロパティとして渡されるようにする
  • Code autocompletion in modern IDEs such as VSCode
  • イベントの詳細
  • コンポーネントのメソッドの署名

These public types are automatically generated by Stencil in src/component.d.ts. This file allows for strong typing in JSX (just like React) and HTMLElement interfaces for each component.

ヒント

It is recommended that this file be checked in with the rest of your code in source control.

Because Web Components generated by Stencil are just vanilla Web Components, they extend the HTMLElement interface. For each component a type named HTML{CamelCaseTag}Element is registered at the global scope. This means developers DO NOT have to import them explicitly, just like HTMLElement or HTMLScriptElement are not imported.

  • ion-button => HTMLIonButtonElement
  • ion-menu-controller => HTMLIonMenuControllerElement
const button: HTMLIonButtonElement = document.queryElement('ion-button');
button.fill = 'outline';

重要:コンポーネントへの参照を保持するために、常に HTML{}Elementインターフェースを使用してください。

Properties​

This section has moved to Property Types

Required Properties​

This section has moved to Required Properties