Skip to content

🎥 Make videos programmatically with React

Restore type-safe InferZodInput in player and web-renderer

Jonny Burger98dd6f12a2d5
diff --git a/packages/player/src/utils/props-if-has-props.ts b/packages/player/src/utils/props-if-has-props.ts
index 1fe5641cdb..4523136e9e 100644
--- a/packages/player/src/utils/props-if-has-props.ts
+++ b/packages/player/src/utils/props-if-has-props.ts
@@ -1,5 +1,13 @@
import type {AnyZodObject} from 'remotion';
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+type InferZodInput<T> = T extends {_zod: {input: any}}
+ ? T['_zod']['input']
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ T extends {_input: any}
+ ? T['_input']
+ : Record<string, unknown>;
+
export type PropsIfHasProps<
Schema extends AnyZodObject,
Props,
@@ -7,7 +15,7 @@ export type PropsIfHasProps<
? {} extends Props
? {
// Neither props nor schema specified
- inputProps?: Record<string, unknown> & Props;
+ inputProps?: InferZodInput<Schema> & Props;
}
: {
// Only props specified
@@ -16,9 +24,9 @@ export type PropsIfHasProps<
: {} extends Props
? {
// Only schema specified
- inputProps: Record<string, unknown>;
+ inputProps: InferZodInput<Schema>;
}
: {
// Props and schema specified
- inputProps: Record<string, unknown> & Props;
+ inputProps: InferZodInput<Schema> & Props;
};
diff --git a/packages/web-renderer/src/props-if-has-props.ts b/packages/web-renderer/src/props-if-has-props.ts
index ca6b69edc9..fda246247d 100644
--- a/packages/web-renderer/src/props-if-has-props.ts
+++ b/packages/web-renderer/src/props-if-has-props.ts
@@ -1,6 +1,14 @@
import type {ComponentType} from 'react';
import type {AnyZodObject, CalculateMetadataFunction} from 'remotion';
+// eslint-disable-next-line @typescript-eslint/no-explicit-any
+type InferZodInput<T> = T extends {_zod: {input: any}}
+ ? T['_zod']['input']
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ T extends {_input: any}
+ ? T['_input']
+ : Record<string, unknown>;
+
export type InferProps<
Schema extends AnyZodObject,
Props extends Record<string, unknown>,
@@ -12,9 +20,9 @@ export type InferProps<
Props
: {} extends Props
? // Only schema specified
- Record<string, unknown>
+ InferZodInput<Schema>
: // Props and schema specified
- Record<string, unknown> & Props;
+ InferZodInput<Schema> & Props;
export type DefaultPropsIfHasProps<
Schema extends AnyZodObject,
@@ -23,7 +31,7 @@ export type DefaultPropsIfHasProps<
? {} extends Props
? {
// Neither props nor schema specified
- defaultProps?: Record<string, unknown> & Props;
+ defaultProps?: InferZodInput<Schema> & Props;
}
: {
// Only props specified
@@ -32,11 +40,11 @@ export type DefaultPropsIfHasProps<
: {} extends Props
? {
// Only schema specified
- defaultProps: Record<string, unknown>;
+ defaultProps: InferZodInput<Schema>;
}
: {
// Props and schema specified
- defaultProps: Record<string, unknown> & Props;
+ defaultProps: InferZodInput<Schema> & Props;
};
type LooseComponentType<T> = ComponentType<T> | ((props: T) => React.ReactNode);
diff --git a/packages/web-renderer/src/render-media-on-web.tsx b/packages/web-renderer/src/render-media-on-web.tsx
index 4f8bb2a985..b783429471 100644
--- a/packages/web-renderer/src/render-media-on-web.tsx
+++ b/packages/web-renderer/src/render-media-on-web.tsx
@@ -225,7 +225,7 @@ const internalRenderMediaOnWeb = async <
const resolved = await Internals.resolveVideoConfig({
calculateMetadata:
- (composition.calculateMetadata as CalculateMetadataFunction<
+ (composition.calculateMetadata as unknown as CalculateMetadataFunction<
InferProps<AnyZodObject, Record<string, unknown>>
>) ?? null,
signal: signal ?? new AbortController().signal,
diff --git a/packages/web-renderer/src/render-still-on-web.tsx b/packages/web-renderer/src/render-still-on-web.tsx
index fc287a08f0..32c1110e1d 100644
--- a/packages/web-renderer/src/render-still-on-web.tsx
+++ b/packages/web-renderer/src/render-still-on-web.tsx
@@ -80,7 +80,7 @@ async function internalRenderStillOnWeb<
const resolved = await Internals.resolveVideoConfig({
calculateMetadata:
- (composition.calculateMetadata as CalculateMetadataFunction<
+ (composition.calculateMetadata as unknown as CalculateMetadataFunction<
InferProps<AnyZodObject, Record<string, unknown>>
>) ?? null,
signal: signal ?? new AbortController().signal,