From c8f0ba9d659db4e6c684fd0e55353ab01d2ec74c Mon Sep 17 00:00:00 2001 From: adm01-debug Date: Sun, 24 May 2026 08:53:14 -0300 Subject: [PATCH] fix(ts): consolida tipos globais Web Speech API em browser.d.ts (-8 erros baseline)\n\nElimina 8 erros (TS2304/TS2552/TS2687/TS2717) do cluster Web Speech API,\nconsolidando as declaracoes em uma unica fonte canonica.\n\nProblema: havia 3 blocos 'declare global { interface Window }' conflitantes\n(browser.d.ts com props opcionais typeof SpeechRecognition; useSpeechRecognition.ts\ncom new()=>SpeechRecognition; SearchWithSuggestions.tsx com webkitSpeechRecognition:\ntypeof SpeechRecognition) + interfaces module-local divergentes em 3 arquivos. O\nlib.dom desta versao do TS (5.4.5) NAO declara SpeechRecognition, SpeechRecognitionEvent,\nSpeechRecognitionErrorEvent nem webkitSpeechRecognition (so tem Alternative/Result/\nResultList), entao os tipos faltantes eram resolvidos como 'any' (TS2717 comprova).\n\nSolucao: browser.d.ts vira a unica declaracao:\n- Window.SpeechRecognition/webkitSpeechRecognition agora NAO-opcionais (typeof\n SpeechRecognition) -> call-sites sem guard (new SpeechRecognition()) param de tipo.\n- declara global interface SpeechRecognition (superset: maxAlternatives + onspeechend\n p/ webSpeechFallback/ChatInputBar), SpeechRecognitionEvent, SpeechRecognitionErrorEvent\n (message opcional p/ compat com handler Event&{error} do fallback) e var SpeechRecognition.\n- remove os blocos declare-global locais de useSpeechRecognition.ts e\n SearchWithSuggestions.tsx, e as interfaces Web Speech duplicadas do hook\n (mantidos UseSpeechRecognitionOptions + tipo de retorno SpeechRecognitionResult).\n\nwebSpeechFallback.ts NAO foi tocado (interfaces locais ja compativeis com a global).\n\nValidacao (binario direto node_modules/.bin/tsc): 1013 -> 1005 (-8); todos os erros\nSpeech/Recognition/webkit eliminados; regressao normalizada vazia; vite build exit 0;\neslint limpo nos 3 arquivos (nenhum estava no eslint-baseline); .tsc-baseline.json intocado. --- .../search/SearchWithSuggestions.tsx | 7 --- .../intelligence/useSpeechRecognition.ts | 49 ------------------- src/types/browser.d.ts | 41 +++++++++++++++- 3 files changed, 39 insertions(+), 58 deletions(-) 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; +};