Skip to content

refactor: make Swift forward-declaration collection polymorphic (#1846) - #2020

Open
dhruvpatel374 wants to merge 1 commit into
margelo:mainfrom
dhruvpatel374:refactor/polymorphic-forward-declarations
Open

dhruvpatel374 wants to merge 1 commit into
margelo:mainfrom
dhruvpatel374:refactor/polymorphic-forward-declarations

Conversation

@dhruvpatel374

Copy link
Copy Markdown

Part of #1846 — implements Option 3 (the standalone cleanup) only.

What

Two files (createSwiftCxxBridge and createSwiftUmbrellaHeader) had
identical 6-line blocks that checked kind === 'hybrid-object', cast
with getTypeAs, and reconstructed the same getForwardDeclaration
call. That is exactly the "checking for concrete type classes at
callers" that Option 3 of #1846 describes.

This moves the knowledge into HybridObjectType via an optional method
on the Type interface:

// Type.ts — new optional capability
getForwardDeclarations?(): string[]

// HybridObjectType.ts — owns it once
getForwardDeclarations(): string[] {
  const name = getHybridObjectName(this.hybridObjectName)
  return [getForwardDeclaration('class', name.HybridTSpecCxx,
    this.sourceConfig.getIosModuleName())]
}

// both callers — now one line each
.flatMap((t) => t.getForwardDeclarations?.() ?? [])

…elo#1846)

Move the knowledge of how to produce a Swift-Cxx forward declaration
out of two identical caller-side type-checks and into HybridObjectType
itself via an optional Type interface method.

Before: both createSwiftCxxBridge and createSwiftUmbrellaHeader had to
independently check `kind === 'hybrid-object'`, cast with getTypeAs,
and reconstruct the same getForwardDeclaration call.

After: HybridObjectType implements getForwardDeclarations() once.
Both callers collapse to flatMap(t => t.getForwardDeclarations?.() ?? []).
Any future type that needs Swift forward declarations just implements
the method — callers do not change.

Also fixes a pre-existing TypeScript error in createSwiftCxxBridge where
.filter((b) => b != null) did not narrow the type, causing b?.dependencies
to spread undefined. Replaced with a proper type-guard predicate.

Generated output is identical — confirmed with bun specs (zero diff on
all generated files). Typecheck and all offline tests pass.
@vercel

vercel Bot commented Oct 30, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
nitro-docs Skipped Skipped Oct 30, 2026 6:13am UTC

Request Review

This branch was previously deployed

1 inactive deployment
Preview — f52d88e7 Deployed Oct 30, 2026 by vercel[bot]
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