Skip to content

The swiss army knife of lossless video/audio editing

improve types

Mikael Finstad2510311e4b5c
diff --git a/src/main/compatPlayer.ts b/src/main/compatPlayer.ts
index f828c267..8e2b9fb1 100644
--- a/src/main/compatPlayer.ts
+++ b/src/main/compatPlayer.ts
@@ -69,7 +69,7 @@ export function createMediaSourceStream(params: Parameters<typeof createMediaSou
return;
}
- logger.warn((err as Error).message);
+ logger.warn(err instanceof Error ? err.message : String(err));
logger.warn(stderr.toString('utf8'));
}
})();
diff --git a/src/renderer/src/components/ExportConfirm.tsx b/src/renderer/src/components/ExportConfirm.tsx
index 17529d2c..ce765afc 100644
--- a/src/renderer/src/components/ExportConfirm.tsx
+++ b/src/renderer/src/components/ExportConfirm.tsx
@@ -495,7 +495,7 @@ function ExportConfirm({
</td>
<td>
<Select value={preserveMetadata} onChange={(e) => setPreserveMetadata(e.target.value as PreserveMetadata)} style={{ height: 20, marginLeft: 5 }}>
- <option value={'default' as PreserveMetadata}>{t('Default')}</option>
+ <option value={'default' satisfies PreserveMetadata}>{t('Default')}</option>
<option value={'none' satisfies PreserveMetadata}>{t('None')}</option>
<option value={'nonglobal' satisfies PreserveMetadata}>{t('Non-global')}</option>
</Select>
@@ -607,7 +607,7 @@ function ExportConfirm({
</td>
<td>
<Select value={avoidNegativeTs} onChange={(e) => setAvoidNegativeTs(e.target.value as AvoidNegativeTs)} style={{ height: 20, marginLeft: 5 }}>
- <option value={'auto' as AvoidNegativeTs}>auto</option>
+ <option value={'auto' satisfies AvoidNegativeTs}>auto</option>
<option value={'make_zero' satisfies AvoidNegativeTs}>make_zero</option>
<option value={'make_non_negative' satisfies AvoidNegativeTs}>make_non_negative</option>
<option value={'disabled' satisfies AvoidNegativeTs}>disabled</option>
diff --git a/src/renderer/src/components/OutputFormatSelect.tsx b/src/renderer/src/components/OutputFormatSelect.tsx
index 6b1501dc..31a164c0 100644
--- a/src/renderer/src/components/OutputFormatSelect.tsx
+++ b/src/renderer/src/components/OutputFormatSelect.tsx
@@ -1,17 +1,17 @@
import { CSSProperties, memo, useMemo } from 'react';
import i18n from 'i18next';
-import allOutFormats from '../outFormats';
+import allOutFormats, { FfmpegFormat } from '../outFormats';
import { withBlur } from '../util';
import Select from './Select';
-const commonVideoAudioFormats = ['matroska', 'mov', 'mp4', 'mpegts', 'ogv', 'webm'];
-const commonAudioFormats = ['flac', 'ipod', 'mp3', 'oga', 'ogg', 'opus', 'wav'];
-const commonSubtitleFormats = ['ass', 'srt', 'sup', 'webvtt'];
+const commonVideoAudioFormats = ['matroska', 'mov', 'mp4', 'mpegts', 'ogv', 'webm'] as const;
+const commonAudioFormats = ['flac', 'ipod', 'mp3', 'oga', 'ogg', 'opus', 'wav'] as const;
+const commonSubtitleFormats = ['ass', 'srt', 'sup', 'webvtt'] as const;
-function renderFormatOptions(formats: string[]) {
+function renderFormatOptions(formats: FfmpegFormat[]) {
return formats.map((format) => (
- <option key={format} value={format}>{format} - {(allOutFormats as Record<string, string>)[format]}</option>
+ <option key={format} value={format}>{format} - {allOutFormats[format]}</option>
));
}
@@ -23,7 +23,7 @@ function OutputFormatSelect({ style, detectedFileFormat, fileFormat, onOutputFor
const commonSubtitleFormatsExceptDetectedFormat = useMemo(() => commonSubtitleFormats.filter((f) => f !== detectedFileFormat), [detectedFileFormat]);
const commonFormatsAndDetectedFormat = useMemo(() => new Set([...commonVideoAudioFormats, ...commonAudioFormats, commonSubtitleFormats, detectedFileFormat]), [detectedFileFormat]);
- const otherFormats = useMemo(() => Object.keys(allOutFormats).filter((format) => !commonFormatsAndDetectedFormat.has(format)), [commonFormatsAndDetectedFormat]);
+ const otherFormats = useMemo(() => (Object.keys(allOutFormats) as (keyof typeof allOutFormats)[]).filter((format) => !commonFormatsAndDetectedFormat.has(format)), [commonFormatsAndDetectedFormat]);
return (
// eslint-disable-next-line react/jsx-props-no-spreading
diff --git a/src/renderer/src/outFormats.ts b/src/renderer/src/outFormats.ts
index bb43dbab..d33857a1 100644
--- a/src/renderer/src/outFormats.ts
+++ b/src/renderer/src/outFormats.ts
@@ -150,4 +150,6 @@ const modifiedFormats = {
modifiedFormats.ipod = 'M4A - Audio for iTunes';
+export type FfmpegFormat = keyof typeof modifiedFormats;
+
export default modifiedFormats;