diff --git a/src/definitions.ts b/src/definitions.ts index 6c5f609..5d4edd4 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -1,5 +1,13 @@ import type { PermissionState, PluginListenerHandle } from '@capacitor/core'; +type EventName = 'partialResults' | 'listeningState'; + +type EventData = T extends 'partialResults' + ? { matches: string[] } + : T extends 'listeningState' + ? { status: 'started' | 'stopped' } + : never; + export interface PermissionStatus { /** * Permission state for speechRecognition alias. @@ -81,28 +89,21 @@ export interface SpeechRecognitionPlugin { */ requestPermissions(): Promise; /** - * Called when partialResults set to true and result received. + * Event: partialResults Called when partialResults set to true and result received. + * Event: listeningState Called when listening state changed. * * On Android it doesn't work if popup is true. * * Provides partial result. * - * @since 2.0.2 + * @since 2.0.2 (partialResults) + * @since 6.0.0 (listeningState) */ - addListener( - eventName: 'partialResults', - listenerFunc: (data: { matches: string[] }) => void, + addListener( + eventName: T, + listenerFunc: (data: EventData) => void, ): Promise & PluginListenerHandle; - /** - * Called when listening state changed. - * - * @since 6.0.0 - */ - addListener( - eventName: 'listeningState', - listenerFunc: (data: { status: 'started' | 'stopped' }) => void, - ): Promise & PluginListenerHandle; /** * Remove all the listeners that are attached to this plugin. *