From dc2a2ab863dc53fb2da1c2cea99e59e6d8387803 Mon Sep 17 00:00:00 2001 From: Justin Emery Date: Wed, 19 Jun 2024 10:49:42 +0100 Subject: [PATCH] fix(typescript): type checks on selectedTextTrack, selectedAudioTrack, selectedVideoTrack (#3910) * Fix type checks on selectedTextTrack and selectedAudioTrack * Improve logging * Rename variable for clarity * Apply same fix to selectedVideoTrack * Lint fixes * Update src/Video.tsx Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> * Update src/Video.tsx Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> * Update src/Video.tsx Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> --------- Co-authored-by: Krzysztof Moch Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> --- src/Video.tsx | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/Video.tsx b/src/Video.tsx index 05c5c083..a7bcfc19 100644 --- a/src/Video.tsx +++ b/src/Video.tsx @@ -193,9 +193,16 @@ const Video = forwardRef( if (!selectedTextTrack) { return; } - const type = typeof selectedTextTrack.value; - if (type !== 'number' && type !== 'string') { - console.log('invalid type provided to selectedTextTrack'); + const typeOfValueProp = typeof selectedTextTrack.value; + if ( + typeOfValueProp !== 'number' && + typeOfValueProp !== 'string' && + typeOfValueProp !== 'undefined' + ) { + console.warn( + 'invalid type provided to selectedTextTrack.value: ', + typeOfValueProp, + ); return; } return { @@ -208,9 +215,16 @@ const Video = forwardRef( if (!selectedAudioTrack) { return; } - const type = typeof selectedAudioTrack.value; - if (type !== 'number' && type !== 'string') { - console.log('invalid type provided to selectedAudioTrack'); + const typeOfValueProp = typeof selectedAudioTrack.value; + if ( + typeOfValueProp !== 'number' && + typeOfValueProp !== 'string' && + typeOfValueProp !== 'undefined' + ) { + console.warn( + 'invalid type provided to selectedAudioTrack.value: ', + typeOfValueProp, + ); return; } @@ -224,9 +238,16 @@ const Video = forwardRef( if (!selectedVideoTrack) { return; } - const type = typeof selectedVideoTrack.value; - if (type !== 'number' && type !== 'string') { - console.log('invalid type provided to selectedVideoTrack'); + const typeOfValueProp = typeof selectedVideoTrack.value; + if ( + typeOfValueProp !== 'number' && + typeOfValueProp !== 'string' && + typeOfValueProp !== 'undefined' + ) { + console.warn( + 'invalid type provided to selectedVideoTrack.value: ', + typeOfValueProp, + ); return; } return {