TypeScript: AudioContext and webkitAudioContext missing in Window definition in lib.dom.d.ts
For most modern browsers, there exists some type of AudioContext on the window, however the current definition for Window has neither of these.
- In some browsers, the audio context exists at
window.AudioContext - In some browsers, the audio context exists at
window.webkitAudioContext
I would expect the definition of Window in lib.dom.d.ts too look something similar to this:
interface Window extends EventTarget, WindowTimers, WindowSessionStorage, WindowLocalStorage, WindowConsole, GlobalEventHandlers, IDBEnvironment, WindowBase64, GlobalFetch, WindowOrWorkerGlobalScope, WindowEventHandlers {
AudioContext?: typeof AudioContext;
webkitAudioContext?: typeof AudioContext;
...
Search Terms: AudioContext, webkitAudioContext , audio context missing in window
Code
window.AudioContext
window.webkitAudioContext
Expected behavior: AudioContext and webkitAudioContext are defined on the window object
Actual behavior: AudioContext and webkitAudioContext are not defined on the window object
Playground Link: https://www.typescriptlang.org/play/#src=window.AudioContext window.webkitAudioContext
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 13
- Comments: 16 (5 by maintainers)
For anyone else running into this, in the meantime you can extend the window in your
declarations.d.tsfile like so:I’ve had to take this approach a handful of times when vendor prefixed APIs aren’t included in
lib.dom.d.tswebkitAudioContext is old naming conventions in the Web Audio which is now the AudioContext.
which i think nothing will be done anytime soon.
The way around is to add
remember to make sure your declaration files are added into you tsconfig.json