Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Typing Errors in interfaces #481

Open
etiennelenhart opened this issue May 30, 2023 · 0 comments
Open

[Question] Typing Errors in interfaces #481

etiennelenhart opened this issue May 30, 2023 · 0 comments

Comments

@etiennelenhart
Copy link

I really like the idea of type-safe errors but still struggle on how to correctly define them in interfaces.

Let's say I have the following interface for an AI prompt template with a create() and validate() method. Both of these may produce different errors so I added generic type parameters for TCreateError and TValidateError. While this works, it of course scales with the amount of methods and gets pretty unwieldy.

Am I doing this wrong? Should I define the errors upfront (Result<Prompt<TSettings, TData>, CreateError>)? I wanted to give implementing classes the option to define multiple "sub-errors" to provide more fine-grained errors as a union.

export interface Template<
  TSettings extends AiModelSettings,
  TData extends PromptData,
  TParameters extends PromptParameters,
  TModelGeneration extends AiModelGeneration,
  TGeneration,
  TCreateError,
  TValidateError
> {
  readonly id: TemplateId
  readonly workspaceId: WorkspaceId
  readonly aiModelId: AiModelId
  readonly name: string
  readonly settings: TSettings
  readonly data: TData

  create(args: TParameters): Result<Prompt<TSettings, TData>, TCreateError>
  validate(generation: Generation<TModelGeneration>): Result<Generation<TGeneration>, TValidateError>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant