fix: resolve all TypeScript strict null check errors
Fix ~68 pre-existing strict null errors across 13 feature modules. Add non-null assertions for DOM element lookups, null coalescing for optional values, and type guards for nullable properties. Zero tsc errors now with --noEmit.
This commit is contained in:
@@ -58,7 +58,7 @@ export async function showAudioSourceModal(sourceType: any, editData?: any) {
|
||||
? (editData.source_type === 'mono' ? 'audio_source.edit.mono' : 'audio_source.edit.multichannel')
|
||||
: (sourceType === 'mono' ? 'audio_source.add.mono' : 'audio_source.add.multichannel');
|
||||
|
||||
document.getElementById('audio-source-modal-title').innerHTML = `${ICON_MUSIC} ${t(titleKey)}`;
|
||||
document.getElementById('audio-source-modal-title')!.innerHTML = `${ICON_MUSIC} ${t(titleKey)}`;
|
||||
(document.getElementById('audio-source-id') as HTMLInputElement).value = isEdit ? editData.id : '';
|
||||
(document.getElementById('audio-source-error') as HTMLElement).style.display = 'none';
|
||||
|
||||
@@ -253,12 +253,12 @@ function _filterDevicesBySelectedTemplate() {
|
||||
const template = templates.find(t => t.id === templateId);
|
||||
const engineType = template ? template.engine_type : null;
|
||||
|
||||
let devices = [];
|
||||
let devices: any[] = [];
|
||||
if (engineType && _cachedDevicesByEngine[engineType]) {
|
||||
devices = _cachedDevicesByEngine[engineType];
|
||||
} else {
|
||||
for (const devList of Object.values(_cachedDevicesByEngine)) {
|
||||
devices = devices.concat(devList);
|
||||
devices = devices.concat(devList as any[]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,9 +370,9 @@ export function testAudioSource(sourceId: any) {
|
||||
_testAudioPeaks.fill(0);
|
||||
_testBeatFlash = 0;
|
||||
|
||||
document.getElementById('audio-test-rms').textContent = '---';
|
||||
document.getElementById('audio-test-peak').textContent = '---';
|
||||
document.getElementById('audio-test-beat-dot').classList.remove('active');
|
||||
document.getElementById('audio-test-rms')!.textContent = '---';
|
||||
document.getElementById('audio-test-peak')!.textContent = '---';
|
||||
document.getElementById('audio-test-beat-dot')!.classList.remove('active');
|
||||
|
||||
testAudioModal.open();
|
||||
|
||||
@@ -382,7 +382,7 @@ export function testAudioSource(sourceId: any) {
|
||||
|
||||
// Connect WebSocket
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
const wsUrl = `${protocol}//${window.location.host}${API_BASE}/audio-sources/${sourceId}/test/ws?token=${encodeURIComponent(apiKey)}`;
|
||||
const wsUrl = `${protocol}//${window.location.host}${API_BASE}/audio-sources/${sourceId}/test/ws?token=${encodeURIComponent(apiKey ?? '')}`;
|
||||
|
||||
try {
|
||||
_testAudioWs = new WebSocket(wsUrl);
|
||||
@@ -434,7 +434,7 @@ function _cleanupTest() {
|
||||
}
|
||||
|
||||
function _sizeCanvas(canvas: HTMLCanvasElement) {
|
||||
const rect = canvas.parentElement.getBoundingClientRect();
|
||||
const rect = canvas.parentElement!.getBoundingClientRect();
|
||||
const dpr = window.devicePixelRatio || 1;
|
||||
canvas.width = rect.width * dpr;
|
||||
canvas.height = 200 * dpr;
|
||||
@@ -463,8 +463,7 @@ export function initAudioSourceDelegation(container: HTMLElement): void {
|
||||
if (!btn) return;
|
||||
|
||||
const action = btn.dataset.action;
|
||||
const id = btn.dataset.id;
|
||||
if (!action || !id) return;
|
||||
if (!action) return;
|
||||
|
||||
// Only handle audio-source actions (prefixed with audio-)
|
||||
const handler = _audioSourceActions[action];
|
||||
@@ -472,6 +471,9 @@ export function initAudioSourceDelegation(container: HTMLElement): void {
|
||||
// Verify we're inside an audio source section
|
||||
const section = btn.closest<HTMLElement>('[data-card-section="audio-multi"], [data-card-section="audio-mono"]');
|
||||
if (!section) return;
|
||||
const card = btn.closest<HTMLElement>('[data-id]');
|
||||
const id = card?.getAttribute('data-id');
|
||||
if (!id) return;
|
||||
e.stopPropagation();
|
||||
handler(id);
|
||||
}
|
||||
@@ -530,12 +532,12 @@ function _renderAudioSpectrum() {
|
||||
}
|
||||
|
||||
// Update stats
|
||||
document.getElementById('audio-test-rms').textContent = (data.rms * 100).toFixed(1) + '%';
|
||||
document.getElementById('audio-test-peak').textContent = (data.peak * 100).toFixed(1) + '%';
|
||||
document.getElementById('audio-test-rms')!.textContent = (data.rms * 100).toFixed(1) + '%';
|
||||
document.getElementById('audio-test-peak')!.textContent = (data.peak * 100).toFixed(1) + '%';
|
||||
const beatDot = document.getElementById('audio-test-beat-dot');
|
||||
if (data.beat) {
|
||||
beatDot.classList.add('active');
|
||||
beatDot!.classList.add('active');
|
||||
} else {
|
||||
beatDot.classList.remove('active');
|
||||
beatDot!.classList.remove('active');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user