🎥 Make videos programmatically with React
Fix InferProps to preserve schema type inference for v3 and v4
Jonny Burger473eb0c3d459
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsxindex 11bde1371d..e04fc36d77 100644--- a/packages/core/src/Composition.tsx+++ b/packages/core/src/Composition.tsx@@ -8,6 +8,7 @@ import {CanUseRemotionHooksProvider,} from './CanUseRemotionHooks.js';import type {Codec} from './codec.js';+import type {TComposition} from './CompositionManager.js';import {CompositionSetters} from './CompositionManagerContext.js';import {FolderContext} from './Folder.js';import {serializeThenDeserializeInStudio} from './input-props-serialization.js';@@ -197,12 +198,12 @@ const InnerComposition = <component: lazy,defaultProps: serializeThenDeserializeInStudio((defaultProps ?? {}) as z.output<Schema> & Props,- ) as z.output<Schema> & Props,+ ) as InferProps<Schema, Props>,nonce,parentFolderName: parentName,schema: schema ?? null,calculateMetadata: compProps.calculateMetadata ?? null,- });+ } as TComposition<Schema, Props>);return () => {unregisterComposition(id);diff --git a/packages/core/src/props-if-has-props.ts b/packages/core/src/props-if-has-props.tsindex 211a9e0fcc..2ff9fcc6ca 100644--- a/packages/core/src/props-if-has-props.ts+++ b/packages/core/src/props-if-has-props.ts@@ -6,6 +6,19 @@ type And<A extends boolean, B extends boolean> = A extends true: false: false;+/**+ * Infer the input type of a zod schema using structural typing.+ * v3 schemas have `_input` phantom type.+ * v4 schemas have `_zod.input` phantom type.+ */+// 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 extends Record<string, unknown>,@@ -34,6 +47,6 @@ 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;diff --git a/packages/template-code-hike/src/calculate-metadata/schema.ts b/packages/template-code-hike/src/calculate-metadata/schema.tsindex 99b2d8231f..d1a374b3e8 100644--- a/packages/template-code-hike/src/calculate-metadata/schema.ts+++ b/packages/template-code-hike/src/calculate-metadata/schema.ts@@ -7,7 +7,7 @@ export const width = z.discriminatedUnion("type", [}),z.object({type: z.literal("fixed"),- value: z.number().step(1),+ value: z.number().multipleOf(1),}),]);