Skip to content

Port TypeScript PR #60195: Assume that type node annotations resolving to error types can be reused #1122

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

Closed
wants to merge 2 commits into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 9, 2025

This PR ports the changes from TypeScript PR #60195 to prevent cascading errors in isolated declarations when type annotations resolve to error types.

Problem

When a type annotation resolves to an error type (e.g., due to an unresolved import), the type checker would previously refuse to reuse the existing type node, leading to additional confusing error messages beyond the original resolution error.

Solution

Added an early return in tryReuseExistingNonParameterTypeNode that allows type node reuse when the annotation type is an error type. This prevents cascading errors while maintaining correct behavior for valid types.

Key changes:

  • Added check if annotationType != nil && b.ch.isErrorType(annotationType) after resolving annotation type
  • Return existing type node to allow reuse when annotation resolves to error type
  • Includes the same explanatory comment from the original TypeScript change

Example

// This would previously generate cascading errors
import { Unresolved } from "nonexistent-module"; // Error: Cannot find module

export const foo = (param?: Unresolved): void => {}; // No additional confusing errors

The change ensures that when Unresolved fails to resolve, we don't generate additional type mismatch errors for the parameter type annotation.

Testing

  • All existing tests pass
  • No baseline changes required (change only affects error cases)
  • Verified the fix resolves the null pointer dereference that occurred during testing

Fixes #1118.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Port TypeScript PR #60195: Assume that type node annotations resolving to error types can be reused Port TypeScript PR #60195: Assume that type node annotations resolving to error types can be reused Jun 9, 2025
@Copilot Copilot AI requested a review from andrewbranch June 9, 2025 22:55
Copilot finished work on behalf of andrewbranch June 9, 2025 22:56
@jakebailey jakebailey deleted the copilot/fix-1118 branch June 24, 2025 23:56
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.

Port TypeScript PR #60195: Assume that type node annotations resolving to error types can be reused
2 participants