Skip to content

feat: branded types for context, subcontext and features#11

Merged
ivklgn merged 2 commits intomainfrom
feat/branded-types
Jun 2, 2025
Merged

feat: branded types for context, subcontext and features#11
ivklgn merged 2 commits intomainfrom
feat/branded-types

Conversation

@ivklgn
Copy link
Owner

@ivklgn ivklgn commented May 30, 2025

now we can infer types from subcontext or features:

  const createErrorContext = createError([{ errorType: "ErrorType1" }, { errorType: "ErrorType2" }] as const);

  const errorContext1 = createErrorContext("Context1"); // infer: ErrorSubcontext<"Context1", "ErrorType1" | "ErrorType2">
  const errorContext2 = createErrorContext("Context2"); // infer: ErrorSubcontext<"Context2", "ErrorType1" | "ErrorType2">

  const featureError = errorContext.feature("Feature"); // infer: ErrorFeature<"Feature", "ErrorType1" | "ErrorType2">

as a result, we can more strictly specify the accepted contexts/features in our code

function foo(errorCtx: typeof errorContext1);

@ivklgn ivklgn merged commit b23c951 into main Jun 2, 2025
10 checks passed
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

Successfully merging this pull request may close these issues.

1 participant