Description
🔎 Search Terms
Problem Description:
The AudioContextState enum type definition in lib.dom.d.ts currently lacks the "interrupted" state. This state is part of the Web Audio API specification and is already implemented and used in certain browser environments (notably WebKit/Safari).
When AudioContext.state reports "interrupted" in a browser (e.g., Safari on iOS/macOS), TypeScript raises a ts(2367) error because "interrupted" is not included in the defined union type for AudioContextState.
Observed Behavior:
When running Web Audio API code in Safari (macOS Sonoma 14.5, iOS Safari), AudioContext.state can transition to "interrupted" (e.g., upon screen lock with navigator.audioSession.type = "auto", or during a phone call). However, the TypeScript definition for AudioContextState only includes "closed" | "running" | "suspended".
This leads to TypeScript errors when attempting to check for or handle the "interrupted" state:
const audioCtx = new AudioContext();
audioCtx.onstatechange = () => {
// TypeScript will issue an error here (e.g., ts(2367))
// because "interrupted" is not a known literal in AudioContextState
if (audioCtx.state === "interrupted") {
console.log("AudioContext was interrupted by the UA.");
}
};
References:
🕗 Version & Regression Information
NONE
⏯ Playground Link
NONE
💻 Code
const audioCtx = new AudioContext();
audioCtx.onstatechange = () => {
// TypeScript will issue an error here (e.g., ts(2367))
// because "interrupted" is not a known literal in AudioContextState
if (audioCtx.state === "interrupted") {
console.log("AudioContext was interrupted by the UA.");
}
};
🙁 Actual behavior
TypeScript raises a ts(2367) error: This comparison appears to be unintentional because the types 'AudioContextState' and '"interrupted"' have no overlap.ts(2367)
🙂 Expected behavior
The AudioContextState type definition in lib.dom.d.ts should be updated to include the "interrupted" state, reflecting its presence in modern Web Audio API implementations and ongoing specification discussions.
Additional information about the issue
see references