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 <krzysmoch.programs@gmail.com>
Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com>
This commit is contained in:
Justin Emery 2024-06-19 10:49:42 +01:00 committed by GitHub
parent 87e7f42042
commit dc2a2ab863
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -193,9 +193,16 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!selectedTextTrack) { if (!selectedTextTrack) {
return; return;
} }
const type = typeof selectedTextTrack.value; const typeOfValueProp = typeof selectedTextTrack.value;
if (type !== 'number' && type !== 'string') { if (
console.log('invalid type provided to selectedTextTrack'); typeOfValueProp !== 'number' &&
typeOfValueProp !== 'string' &&
typeOfValueProp !== 'undefined'
) {
console.warn(
'invalid type provided to selectedTextTrack.value: ',
typeOfValueProp,
);
return; return;
} }
return { return {
@ -208,9 +215,16 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!selectedAudioTrack) { if (!selectedAudioTrack) {
return; return;
} }
const type = typeof selectedAudioTrack.value; const typeOfValueProp = typeof selectedAudioTrack.value;
if (type !== 'number' && type !== 'string') { if (
console.log('invalid type provided to selectedAudioTrack'); typeOfValueProp !== 'number' &&
typeOfValueProp !== 'string' &&
typeOfValueProp !== 'undefined'
) {
console.warn(
'invalid type provided to selectedAudioTrack.value: ',
typeOfValueProp,
);
return; return;
} }
@ -224,9 +238,16 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
if (!selectedVideoTrack) { if (!selectedVideoTrack) {
return; return;
} }
const type = typeof selectedVideoTrack.value; const typeOfValueProp = typeof selectedVideoTrack.value;
if (type !== 'number' && type !== 'string') { if (
console.log('invalid type provided to selectedVideoTrack'); typeOfValueProp !== 'number' &&
typeOfValueProp !== 'string' &&
typeOfValueProp !== 'undefined'
) {
console.warn(
'invalid type provided to selectedVideoTrack.value: ',
typeOfValueProp,
);
return; return;
} }
return { return {