-
Couldn't load subscription status.
- Fork 55
feat: add type safety for builder configurations with discriminated unions #80
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
base: pranaygp/standardize-method-naming
Are you sure you want to change the base?
feat: add type safety for builder configurations with discriminated unions #80
Conversation
🦋 Changeset detectedLatest commit: 87c62d3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
e832c5b to
9290a95
Compare
bff8430 to
21d8ce1
Compare
| | StandaloneConfig | ||
| | VercelBuildOutputConfig | ||
| | NextConfig; | ||
|
|
There was a problem hiding this comment.
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:
- In the
validBuildTargetsconstant - A valid value for
BuildTargettype - Part of the
WorkflowConfigdiscriminated union viaNextConfig
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>
21d8ce1 to
87c62d3
Compare
9290a95 to
1e73424
Compare

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:
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