feat: Improve typing for recipe runtime #70
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request refactors how the
RecipeRuntimetype is used throughout the codebase, improving type inference and developer ergonomics when working with recipes. The main change is to use type inference and theas const satisfies RecipeRuntimepattern instead of explicit type annotations, and to introduce a new utility type for extracting variant prop types from a recipe definition. This makes recipe usage more type-safe and flexible, especially in test and consumer code.Type inference and type safety improvements:
Updated all test and consumer code to define recipe objects using
const runtime = { ... } as const satisfies RecipeRuntimeinstead of explicit: RecipeRuntimetype annotations. This enables TypeScript to infer literal types for variants and improves type safety. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31] [32] [33] [34] [35]Updated the
createRecipefunction to be generic over the recipe type, allowing it to infer the correct variant prop types from the recipe definition. The function now accepts a generic parameter and uses the newRecipeVariantProps<R>utility type for its props argument.Type utility additions:
RecipeVariantProps<R>utility type totypes.tsthat extracts the correct variant prop types from a given recipe definition. This enables better type inference for recipe props, ensuring that only valid variant keys and values are accepted.Imports and type usage cleanup:
runtime.tsto include the newRecipeVariantPropstype and to reorder imports for clarity.