diff --git a/src/components/search/SearchWithSuggestions.tsx b/src/components/search/SearchWithSuggestions.tsx index 561001fc3..e01e82400 100644 --- a/src/components/search/SearchWithSuggestions.tsx +++ b/src/components/search/SearchWithSuggestions.tsx @@ -197,10 +197,3 @@ export function SearchWithSuggestions({ ); } - -// Add type declaration for SpeechRecognition -declare global { - interface Window { - webkitSpeechRecognition: typeof SpeechRecognition; - } -} diff --git a/src/hooks/intelligence/useSpeechRecognition.ts b/src/hooks/intelligence/useSpeechRecognition.ts index 75fcf53da..b8d8ad567 100644 --- a/src/hooks/intelligence/useSpeechRecognition.ts +++ b/src/hooks/intelligence/useSpeechRecognition.ts @@ -15,55 +15,6 @@ interface SpeechRecognitionResult { error: string | null; } -// TypeScript declarations for Web Speech API -interface SpeechRecognitionEvent extends Event { - results: SpeechRecognitionResultList; - resultIndex: number; -} - -interface SpeechRecognitionResultList { - length: number; - item(index: number): SpeechRecognitionResultItem; - [index: number]: SpeechRecognitionResultItem; -} - -interface SpeechRecognitionResultItem { - isFinal: boolean; - length: number; - item(index: number): SpeechRecognitionAlternative; - [index: number]: SpeechRecognitionAlternative; -} - -interface SpeechRecognitionAlternative { - transcript: string; - confidence: number; -} - -interface SpeechRecognitionErrorEvent extends Event { - error: string; - message: string; -} - -declare global { - interface Window { - SpeechRecognition: new () => SpeechRecognition; - webkitSpeechRecognition: new () => SpeechRecognition; - } -} - -interface SpeechRecognition extends EventTarget { - continuous: boolean; - interimResults: boolean; - lang: string; - start(): void; - stop(): void; - abort(): void; - onresult: ((event: SpeechRecognitionEvent) => void) | null; - onerror: ((event: SpeechRecognitionErrorEvent) => void) | null; - onend: (() => void) | null; - onstart: (() => void) | null; -} - export function useSpeechRecognition({ onResult, onError, diff --git a/src/types/browser.d.ts b/src/types/browser.d.ts index afc8d0da1..b890ece52 100644 --- a/src/types/browser.d.ts +++ b/src/types/browser.d.ts @@ -6,8 +6,8 @@ interface Window { webkitAudioContext?: typeof AudioContext; /** Web Speech API (standard + webkit prefix) */ - SpeechRecognition?: typeof SpeechRecognition; - webkitSpeechRecognition?: typeof SpeechRecognition; + SpeechRecognition: typeof SpeechRecognition; + webkitSpeechRecognition: typeof SpeechRecognition; /** Safari standalone mode detection */ navigator: Navigator & { standalone?: boolean; @@ -20,3 +20,40 @@ interface Navigator { /** Safari standalone mode */ standalone?: boolean; } + +/** + * Web Speech API recognizer types. + * Absent from lib.dom in the TypeScript version used here, so declared once + * globally as the single source of truth (replaces scattered, conflicting + * per-file `declare global` blocks). Shape is a superset compatible with every + * consumer's local usage (maxAlternatives, onspeechend, permissive onerror). + */ +interface SpeechRecognitionEvent extends Event { + results: SpeechRecognitionResultList; + resultIndex: number; +} + +interface SpeechRecognitionErrorEvent extends Event { + error: string; + message?: string; +} + +interface SpeechRecognition extends EventTarget { + continuous: boolean; + interimResults: boolean; + lang: string; + maxAlternatives: number; + start(): void; + stop(): void; + abort(): void; + onresult: ((event: SpeechRecognitionEvent) => void) | null; + onerror: ((event: SpeechRecognitionErrorEvent) => void) | null; + onend: (() => void) | null; + onstart: (() => void) | null; + onspeechend: (() => void) | null; +} + +declare var SpeechRecognition: { + prototype: SpeechRecognition; + new (): SpeechRecognition; +};