types: improve type safety in web demo cast fixtures - #4626
Merged
Conversation
Ten synthetic demo casts built their workflow with `as unknown as Workflow`, so nothing checked them against the transport shape — a cast could drift into an unplayable graph and still compile. One root cause: `castHelpers.GraphNode` declared `dynamic_outputs` as `Record<string, unknown>`, which is not assignable to the protocol `Node`'s `Record<string, PropertyTypeMetadata>`. Everything else already conformed. GraphNode now extends the transport `Node` (so it can't drift again), `edge()` returns `Edge`, and the ten double casts are gone in favor of plain annotations. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I looked for
web/src/,electron/src/, andmobile/src/are already free ofanyin non-test source — every hit for: any,as any,any[],Record<string, any>,Promise<any>outside tests turned out to be the English word "any" inside a comment. The real weak spot isas unknown as, which silences the compiler completely. This PR fixes the largest cluster of those that has a single fixable root cause.The bug in the types
Ten synthetic demo casts each ended their workflow literal with
as unknown as Workflow. That double cast meant nothing checked the fixtures against the transport shape — a cast could drift into an unplayable graph and still compile.The root cause was one line.
castHelpers.GraphNodedeclared:which is not assignable to the protocol
Node'sRecord<string, PropertyTypeMetadata>. Everything else in those literals already conformed — verified by annotating a probe and reading the single resulting error.Changes
web/src/demo/castHelpers.tsGraphNodenowextends Node(the transport type) so it can't drift again;dynamic_outputstypedRecord<string, PropertyTypeMetadata>;edge()given an explicitEdgereturn typeweb/src/demo/cookbook/builders.tscookbookWorkflowreturns a checkedWorkflow;edgesparam typedEdge[]instead ofReturnType<typeof edge>[]chatQaCast.ts,connectRunCast.ts,describeImageCast.ts,listGeneratorCast.ts,sampleCast.ts,summarizeCast.ts,templateMergeCast.ts,tutorialCast.tsas unknown as Workflow→const workflow: Workflow, so each fixture is now checked against the real API shapeCompile-time only — no runtime behavior changed.
Verifying the annotations aren't vacuous
Nodehas an index signature, so an annotation could in principle check nothing. Confirmed it does check: temporarily settingname: 123inconnectRunCast.tsproducesReverted after the check.
Checks
npm run typecheck✅ ·npm run lint✅ ·npm run test✅ (1063 + 63 + 73 suites, 14132 tests)Deliberately left out
web/src/e2e_runner/graphRender.ts:129has the sameas unknown as Workflowand the same root cause, so it's a one-line follow-up. Left out only to stay within the 10-file cap.ApiTypescasts (WorkflowManagerStore,useWorkflowVersions,AssetStore,GlobalChatStore,electron/src/api.ts,mobile/src/hooks/useApplications.ts) are the higher-stakes cluster, and I did not paper over them. They hide a genuine nullability mismatch: the router infersdescription: string | null | undefinedwhile the protocolWorkflowdeclaresdescription: string, andworkflows.examplesreturnsworkflows: unknown[]. Fixing it properly means changingpackages/protocol(outside this task's scope) or adding?? ""normalizers at the boundary (a runtime change this task forbids). Worth its own PR — it's a real defect, not a typing nit.🤖 Generated with Claude Code