pglejzer / timepicker-ui

timepicker-ui is an easy library with timepicker. Fully wrote with TypeScript. This library is based on Material Design from Google.
MIT License
62 stars 18 forks source link

How to convert this code in typescript? #34

Closed iamneaz closed 1 year ago

iamneaz commented 1 year ago

I am new to typescript. I am struggling with this particular code of Accept Event to typescript. this.acceptEvent.addEventListener( "accept", ({ detail: { hour, minutes, type } }) => this.time =${hour}:${minutes} ${type} ); I am struggling to define the type of "detail";

pglejzer commented 1 year ago

You can do something like that:

interface IAcceptEvent {
  detail: {
    hour: string;
    minutes: string;
    type: string;
  };
}

acceptEvent.addEventListener('accept', (event) => {
  const {
    detail: { hour, minutes, type },
  } = event as unknown as IAcceptEvent;

  acceptValue.innerHTML = `${hour}:${minutes} ${type}`;
});