kopia lustrzana https://github.com/shoelace-style/shoelace
Perform type checking of the event detail in the emit function if the event type matches a Shoelace event
rodzic
75bd7784fb
commit
ce708fbba8
|
@ -1,13 +1,19 @@
|
||||||
import { LitElement } from 'lit';
|
import { LitElement } from 'lit';
|
||||||
import { property } from 'lit/decorators.js';
|
import { property } from 'lit/decorators.js';
|
||||||
|
|
||||||
|
type SlEventInit<T> = T extends keyof GlobalEventHandlersEventMap
|
||||||
|
? GlobalEventHandlersEventMap[T] extends CustomEvent
|
||||||
|
? CustomEventInit<GlobalEventHandlersEventMap[T]['detail']>
|
||||||
|
: CustomEventInit
|
||||||
|
: CustomEventInit;
|
||||||
|
|
||||||
export default class ShoelaceElement extends LitElement {
|
export default class ShoelaceElement extends LitElement {
|
||||||
// Make localization attributes reactive
|
// Make localization attributes reactive
|
||||||
@property() dir: string;
|
@property() dir: string;
|
||||||
@property() lang: string;
|
@property() lang: string;
|
||||||
|
|
||||||
/** Emits a custom event with more convenient defaults. */
|
/** Emits a custom event with more convenient defaults. */
|
||||||
emit(name: string, options?: CustomEventInit) {
|
emit<T extends string>(name: T, options?: SlEventInit<T>) {
|
||||||
const event = new CustomEvent(name, {
|
const event = new CustomEvent(name, {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
cancelable: false,
|
cancelable: false,
|
||||||
|
|
Ładowanie…
Reference in New Issue