Skip to content

fix: resolve TypeScript factory return annotations - #10

Merged
NianJiuZst merged 2 commits into
NianJiuZst:mainfrom
hongtaihu:fix/typescript-factory-returns
Nov 2, 2026
Merged

NianJiuZst merged 2 commits into
NianJiuZst:mainfrom
hongtaihu:fix/typescript-factory-returns

Conversation

@hongtaihu

@hongtaihu hongtaihu commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6.

make(): A keeps its return annotation only in the display signature, so const a = make(); a.run() misses A.run even though the annotation identifies its receiver.

Record TypeScript/TSX return annotations as resolver facts and propagate supported nominal types through named functions, variable-initialized arrows/function expressions, and methods. Resolve the type using enclosing declarations and explicit imports, including aliases and re-exports. Named and namespace imports use the type namespace when a type and runtime function share a name. The function body's declarations cannot shadow its return annotation. Unsupported annotations retain an explicit unknown receiver.

Integrated main 2c35e7a, preserving the satisfies and JS/TS resolution changes from PRs #5 and #12. Engine rules advance from 9 to 10 so existing indexes refresh; this PR makes no segment-format or vendored-kernel changes relative to main.

Validation on Linux x86_64, Rust 1.99.1:

  • Reproduced the original issue on c795575 and the function-body shadowing bug on the previous PR head 249dd48; both pass after the fix.
  • Nine added tests cover extraction identity, TS/TSX targets, nested factories, declaration scopes and imports, unsupported returns, and incremental/full parity. The body-shadowing regression checks 24 combinations of factory forms, type declarations, and annotation origins. A separate regression fails without the type-namespace adaptation and passes with it, including an independent runtime-value call.
  • Eight annotation edits and nine function-body declaration edits all use delta sync and equal independent full rebuilds.
  • CGR_SYNC_SEQUENCES=6 CGR_SYNC_STEPS=100 cargo test --offline --locked --workspace: 204 passed, 1 existing ignored.
  • CI package-list formatting, strict workspace Clippy, CLI/MCP/prompt-hook/SQLite smoke, and CLI issue reproduction pass. Smoke uses the upstream script with a synchronous subprocess timeout wrapper.
  • An engine-7 index containing the incorrect body-local target rebuilds with engine 10, replaces that edge with the imported type's method, passes strict checksum verification, and matches a fresh rebuild.

Union/intersection types, generic substitution, arrays, async/generator wrappers, and block-level type shadowing remain outside the supported return rules. No new overall precision/recall, performance, or native macOS/Windows validation claim is made.

Implemented and validated by OpenAI Codex, on behalf of @hongtaihu.

Implemented and validated by OpenAI Codex.
Exclude function-body types from return annotations and resolve imported
return names in the TypeScript type namespace. Merge current main and
advance engine rules to 10 so older indexes refresh.

Validated: 204 tests passed, 1 existing ignored; format, strict Clippy,
CLI/MCP smoke, incremental/full parity, and engine upgrade checks passed.

Implemented and validated by OpenAI Codex on behalf of @hongtaihu.
@NianJiuZst
NianJiuZst merged commit 46745f5 into NianJiuZst:main Nov 2, 2026
9 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.

bug: TypeScript factory return annotations do not resolve method calls

2 participants