Skip to content

Instantly share code, notes, and snippets.

@jodylecompte
jodylecompte / types.ts
Created March 14, 2024 21:39
Original definition of MappedParameterTypes in CopilotKit
export type MappedParameterTypes<T extends Parameter[]> = {
// Check if the parameter has an 'enum' defined
[P in T[number] as P["name"]]: P extends { enum: Array<infer E> }
? E extends string // Ensure the enum values are strings
? P["required"] extends false // Check if the parameter is optional
? E | undefined // If so, include 'undefined' in the type
: E // Otherwise, use the enum type directly
: never // This case should not occur since 'enum' implies string values
: // Handle parameters defined as 'object' with specified attributes
P extends { type: "object"; attributes: infer Attributes }