Skip to content

Conversation

@pranaygp
Copy link
Collaborator

Improves type safety by creating discriminated union types for builder-specific
configurations, making it clear which configuration options are required for
each builder type.

Changes:

  • Created BaseWorkflowConfig interface with common options
  • Created StandaloneConfig, VercelBuildOutputConfig, and NextConfig types
  • Made WorkflowConfig a discriminated union based on buildTarget
  • Added documentation for each configuration type
  • Exported new types from @workflow/builders

This enables better IntelliSense and type checking when constructing builder
configurations, preventing invalid configuration combinations at compile time.

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

@changeset-bot
Copy link

changeset-bot bot commented Oct 26, 2025

🦋 Changeset detected

Latest commit: 87c62d3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@workflow/builders Patch
@workflow/cli Patch
@workflow/next Patch
@workflow/nitro Patch
workflow Patch
@workflow/world-testing Patch
@workflow/ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Oct 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
example-nextjs-workflow-turbopack Ready Ready Preview Comment Oct 26, 2025 7:06am
example-nextjs-workflow-webpack Ready Ready Preview Comment Oct 26, 2025 7:06am
example-workflow Ready Ready Preview Comment Oct 26, 2025 7:06am
workbench-nitro-workflow Ready Ready Preview Comment Oct 26, 2025 7:06am
workflow-docs Ready Ready Preview Comment Oct 26, 2025 7:06am

| StandaloneConfig
| VercelBuildOutputConfig
| NextConfig;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isValidBuildTarget type guard function doesn't include the 'next' build target in its validation logic, but the new discriminated union WorkflowConfig now includes NextConfig with buildTarget: 'next'. This will cause type mismatches and incorrect validation.

View Details
📝 Patch Details
diff --git a/packages/builders/src/types.ts b/packages/builders/src/types.ts
index 8e2ae46..142d550 100644
--- a/packages/builders/src/types.ts
+++ b/packages/builders/src/types.ts
@@ -65,5 +65,5 @@ export type WorkflowConfig =
 export function isValidBuildTarget(
   target: string | undefined
 ): target is BuildTarget {
-  return target === 'standalone' || target === 'vercel-build-output-api';
+  return (validBuildTargets as readonly string[]).includes(target as string);
 }

Analysis

isValidBuildTarget() type guard doesn't validate 'next' build target

What fails: The isValidBuildTarget() type guard function in packages/builders/src/types.ts only validates 'standalone' and 'vercel-build-output-api' targets, but the BuildTarget type and validBuildTargets constant include 'next'. This causes the type guard to return false for a valid discriminant value that is part of the WorkflowConfig union type.

How to reproduce:

import { isValidBuildTarget, validBuildTargets, BuildTarget } from '@workflow/builders';

// validBuildTargets includes 'next'
console.log(validBuildTargets); // ['standalone', 'vercel-build-output-api', 'next']

// But the type guard rejects it
console.log(isValidBuildTarget('next')); // false (BUG)
console.log(isValidBuildTarget('standalone')); // true (works)
console.log(isValidBuildTarget('vercel-build-output-api')); // true (works)

Result: isValidBuildTarget('next') returns false, even though 'next' is:

  1. In the validBuildTargets constant
  2. A valid value for BuildTarget type
  3. Part of the WorkflowConfig discriminated union via NextConfig

This causes type safety violations - code constructing a NextConfig with buildTarget: 'next' would fail validation with the type guard.

Expected: The type guard should return true for all three valid build targets, matching the BuildTarget type definition derived from validBuildTargets.

Fix: Changed the implementation to use the validBuildTargets constant for validation rather than hardcoded literals. This ensures any new build targets added to validBuildTargets are automatically validated, preventing future regressions.

…nions

Improves type safety by creating discriminated union types for builder-specific
configurations, making it clear which configuration options are required for
each builder type.

Changes:
- Created BaseWorkflowConfig interface with common options
- Created StandaloneConfig, VercelBuildOutputConfig, and NextConfig types
- Made WorkflowConfig a discriminated union based on buildTarget
- Added documentation for each configuration type
- Exported new types from @workflow/builders

This enables better IntelliSense and type checking when constructing builder
configurations, preventing invalid configuration combinations at compile time.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

2 participants