Skip to content

[WIP] react class components from ternaries give no construct or call signature upon rendering #1445

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 1 commit into from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 24, 2025

Working on fixing the issue where JSX elements with union types of React class components result in "no construct or call signatures" error.

Progress:

  • Explored repository structure and build system
  • Located the relevant JSX handling code in internal/checker/jsx.go
  • Identified the specific error message (TS2604) and its location in the code
  • Created test cases to reproduce the issue:
    • jsxUnionNoSignatures.tsx - confirms TS2604 error can be triggered
    • jsxUnionWithNonCallable.tsx - reproduces TS2604 with mixed valid/invalid union
    • jsxValidConstructorUnion.tsx - shows that valid constructor unions work
    • Various React component union tests that show related TS2786 errors
  • Analyze the root cause in getUninstantiatedJsxSignaturesOfType function
  • Fix the union type signature handling for JSX components
  • Verify the fix works with the test cases
  • Ensure no regressions in existing functionality

Issue Analysis:

The getUninstantiatedJsxSignaturesOfType function correctly handles:

  1. Unions where some members have no signatures (correctly returns empty, triggers TS2604)
  2. Unions of declared constructor types (works correctly)

The issue appears to be specific to React class components. Further investigation needed to understand why class constructor types might not be detected as having construct signatures in certain contexts.

Test Results:

  • TS2604 error can be reliably triggered with invalid unions
  • Valid constructor unions work as expected
  • React class component unions currently give TS2786 (ElementClass compatibility) rather than TS2604

Fixes #1442.


💡 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.

@jakebailey
Copy link
Member

Completely reset your branch, removing all previous work.

Use this test:

// @strict: true
// @jsx: react-jsx
// @noEmit: true

/// <reference path="/.lib/react16.d.ts" />

import { Component } from "react";

type PropsTest = Readonly<{
  test: string,
}>;

class X extends Component<PropsTest, { yo: string }> {
  static defaultProps = {
    test: "x",
  };

  render() {
    return "test";
  }
}

class Y extends Component<PropsTest, { hey: string }> {
  render() {
    return "test";
  }
}

const XorY = Math.random() > 0.5 ? X : Y;

function z() {
  return <XorY test="test" />;
}

Before working, run the test, accept the baselines, and commit it. Then work on fixing the difference between the code in this repo and the checking in _submodules/TypeScript.

Copy link
Contributor Author

Copilot AI commented Jul 24, 2025

Completely reset your branch, removing all previous work.

Use this test:
...

I've reset the branch completely and added the specific test case you provided. The test has been run and baselines accepted in commit 77bc6b6. The test currently shows XorY being typed as typeof Y instead of the expected union type typeof X | typeof Y. I'm now analyzing the difference with the TypeScript submodule to implement the fix.

@jakebailey
Copy link
Member

I reset the branch and added a test for you in testdata/tests/cases/compiler/reactClassComponentTernary.tsx.

Fix the checker bug causing the error in this file. Remember that you can cross-reference _submodules/TypeScript/src/compiler/checker.ts.

Consider print debugging this by running go test -v -run='TestLocal/reactClassComponentTernary' ./internal/testrunner.

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.

react class components from ternaries give no construct or call signature upon rendering
2 participants