Skip to content

🎥 Make videos programmatically with React

fix type errors in Audio|Video components

Jonny Burger2f4477fddcca
diff --git a/packages/core/src/audio/AudioForDevelopment.tsx b/packages/core/src/audio/AudioForDevelopment.tsx
index ace5887da5..068ec6bd03 100644
--- a/packages/core/src/audio/AudioForDevelopment.tsx
+++ b/packages/core/src/audio/AudioForDevelopment.tsx
@@ -1,3 +1,4 @@
+import type {ForwardRefExoticComponent, RefAttributes} from 'react';
import React, {
forwardRef,
useContext,
@@ -19,11 +20,13 @@ import type {RemotionAudioProps} from './props';
import {useSharedAudio} from './shared-audio-tags';
import {useFrameForVolumeProp} from './use-audio-frame';
+type AudioForDevelopmentProps = RemotionAudioProps & {
+ shouldPreMountAudioTags: boolean;
+};
+
const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
HTMLAudioElement,
- RemotionAudioProps & {
- shouldPreMountAudioTags: boolean;
- }
+ AudioForDevelopmentProps
> = (props, ref) => {
const [initialShouldPreMountAudioElements] = useState(
props.shouldPreMountAudioTags
@@ -102,4 +105,6 @@ const AudioForDevelopmentForwardRefFunction: React.ForwardRefRenderFunction<
export const AudioForDevelopment = forwardRef(
AudioForDevelopmentForwardRefFunction
-);
+) as ForwardRefExoticComponent<
+ AudioForDevelopmentProps & RefAttributes<HTMLAudioElement>
+>;
diff --git a/packages/core/src/audio/AudioForRendering.tsx b/packages/core/src/audio/AudioForRendering.tsx
index ecce045462..b8b1665b09 100644
--- a/packages/core/src/audio/AudioForRendering.tsx
+++ b/packages/core/src/audio/AudioForRendering.tsx
@@ -1,3 +1,4 @@
+import type {ForwardRefExoticComponent, RefAttributes} from 'react';
import React, {
forwardRef,
useContext,
@@ -92,4 +93,6 @@ const AudioForRenderingRefForwardingFunction: React.ForwardRefRenderFunction<
export const AudioForRendering = forwardRef(
AudioForRenderingRefForwardingFunction
-);
+) as ForwardRefExoticComponent<
+ RemotionAudioProps & RefAttributes<HTMLAudioElement>
+>;
diff --git a/packages/core/src/test/not-all-props-in-media-tags.test.ts b/packages/core/src/test/not-all-props-in-media-tags.test.ts
new file mode 100644
index 0000000000..cc3133cf4d
--- /dev/null
+++ b/packages/core/src/test/not-all-props-in-media-tags.test.ts
@@ -0,0 +1,52 @@
+import fs from 'fs';
+import path from 'path';
+import {expect, test} from 'vitest';
+
+// Test for https://github.com/remotion-dev/remotion/issues/1243
+test('Should not have disableRemotePlayback props in the <VideoForDevelopment> component type definition', () => {
+ const file = path.resolve(
+ process.cwd(),
+ 'dist',
+ 'video',
+ 'VideoForDevelopment.d.ts'
+ );
+ const read = fs.readFileSync(file, 'utf-8');
+ expect(read).not.toContain('disableRemotePlayback');
+ expect(read).toContain('volume-prop');
+});
+
+test('Should not have disableRemotePlayback props in the <VideoForRendering> component type definition', () => {
+ const file = path.resolve(
+ process.cwd(),
+ 'dist',
+ 'video',
+ 'VideoForRendering.d.ts'
+ );
+ const read = fs.readFileSync(file, 'utf-8');
+ expect(read).not.toContain('disableRemotePlayback');
+ expect(read).toContain('volume-prop');
+});
+
+test('Should not have disableRemotePlayback props in the <AudioForDevelopment> component type definition', () => {
+ const file = path.resolve(
+ process.cwd(),
+ 'dist',
+ 'audio',
+ 'AudioForDevelopment.d.ts'
+ );
+ const read = fs.readFileSync(file, 'utf-8');
+ expect(read).not.toContain('aria-disabled');
+ expect(read).toContain('volume-prop');
+});
+
+test('Should not have disableRemotePlayback props in the <AudioForRendering> component type definition', () => {
+ const file = path.resolve(
+ process.cwd(),
+ 'dist',
+ 'audio',
+ 'AudioForRendering.d.ts'
+ );
+ const read = fs.readFileSync(file, 'utf-8');
+ expect(read).not.toContain('aria-disabled');
+ expect(read).toContain('volume-prop');
+});
diff --git a/packages/core/src/video/VideoForDevelopment.tsx b/packages/core/src/video/VideoForDevelopment.tsx
index c8d9cc6eba..99c390c256 100644
--- a/packages/core/src/video/VideoForDevelopment.tsx
+++ b/packages/core/src/video/VideoForDevelopment.tsx
@@ -1,3 +1,4 @@
+import type {ForwardRefExoticComponent, RefAttributes} from 'react';
import React, {forwardRef, useEffect, useImperativeHandle, useRef} from 'react';
import {useFrameForVolumeProp} from '../audio/use-audio-frame';
import {useMediaInTimeline} from '../use-media-in-timeline';
@@ -10,11 +11,13 @@ import {
} from '../volume-position-state';
import type {RemotionVideoProps} from './props';
+type VideoForDevelopmentProps = RemotionVideoProps & {
+ onlyWarnForMediaSeekingError: boolean;
+};
+
const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
HTMLVideoElement,
- RemotionVideoProps & {
- onlyWarnForMediaSeekingError: boolean;
- }
+ VideoForDevelopmentProps
> = (props, ref) => {
const videoRef = useRef<HTMLVideoElement>(null);
@@ -94,6 +97,9 @@ const VideoForDevelopmentRefForwardingFunction: React.ForwardRefRenderFunction<
);
};
+// Copy types from forwardRef but not necessary to remove ref
export const VideoForDevelopment = forwardRef(
VideoForDevelopmentRefForwardingFunction
-);
+) as ForwardRefExoticComponent<
+ VideoForDevelopmentProps & RefAttributes<HTMLVideoElement>
+>;
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsx
index 060164df94..50f3ae2d32 100644
--- a/packages/core/src/video/VideoForRendering.tsx
+++ b/packages/core/src/video/VideoForRendering.tsx
@@ -1,3 +1,4 @@
+import type {ForwardRefExoticComponent, RefAttributes} from 'react';
import React, {
forwardRef,
useContext,
@@ -205,4 +206,8 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<
return <video ref={videoRef} {...props} onError={onError} />;
};
-export const VideoForRendering = forwardRef(VideoForRenderingForwardFunction);
+export const VideoForRendering = forwardRef(
+ VideoForRenderingForwardFunction
+) as ForwardRefExoticComponent<
+ RemotionVideoProps & RefAttributes<HTMLVideoElement>
+>;