From 95b4df0ae473ef6f98bf950ff6f9b025011f6a7b Mon Sep 17 00:00:00 2001 From: Idris Gadi Date: Tue, 27 Jan 2026 16:23:45 +0530 Subject: [PATCH] fix: types --- .../video-editor/timeline/TimelineEditor.tsx | 4 ++-- src/utils/aspectRatioUtils.ts | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/video-editor/timeline/TimelineEditor.tsx b/src/components/video-editor/timeline/TimelineEditor.tsx index 4ea851b..bdf9558 100644 --- a/src/components/video-editor/timeline/TimelineEditor.tsx +++ b/src/components/video-editor/timeline/TimelineEditor.tsx @@ -17,7 +17,7 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; -import { type AspectRatio, getAspectRatioLabel } from "@/utils/aspectRatioUtils"; +import { type AspectRatio, getAspectRatioLabel, ASPECT_RATIOS } from "@/utils/aspectRatioUtils"; import { formatShortcut } from "@/utils/platformUtils"; import { TutorialHelp } from "../TutorialHelp"; @@ -896,7 +896,7 @@ export default function TimelineEditor({ - {(['16:9', '9:16', '1:1', '4:3', '4:5', '16:10', "10:16"] as AspectRatio[]).map((ratio) => ( + {ASPECT_RATIOS.map((ratio) => ( onAspectRatioChange(ratio)} diff --git a/src/utils/aspectRatioUtils.ts b/src/utils/aspectRatioUtils.ts index f00167c..1aa3900 100644 --- a/src/utils/aspectRatioUtils.ts +++ b/src/utils/aspectRatioUtils.ts @@ -1,5 +1,12 @@ -export type AspectRatio = '16:9' | '9:16' | '1:1' | '4:3' | '4:5' | '16:10' | '10:16'; +export const ASPECT_RATIOS = ['16:9', '9:16', '1:1', '4:3', '4:5', '16:10', '10:16'] as const; +export type AspectRatio = typeof ASPECT_RATIOS[number]; + +/** + * Returns the numeric value of an aspect ratio. + * Uses exhaustive type checking to ensure all AspectRatio cases are handled. + * If TypeScript errors here, a new ratio was added to the type but not handled. + */ export function getAspectRatioValue(aspectRatio: AspectRatio): number { switch (aspectRatio) { case '16:9': return 16 / 9; @@ -9,7 +16,11 @@ export function getAspectRatioValue(aspectRatio: AspectRatio): number { case '4:5': return 4 / 5; case '16:10': return 16 / 10; case '10:16': return 10 / 16; - default: return 1; + default: { + // Ensures all cases are handled - TypeScript errors if missing + const _exhaustiveCheck: never = aspectRatio; + return _exhaustiveCheck; + } } }