Skip to content

Add getConstraint() and getDefault() getters to TypeParameter#4556

Draft
andrewbranch with Copilot wants to merge 2 commits into
mainfrom
copilot/add-get-constraint-and-get-default
Draft

Add getConstraint() and getDefault() getters to TypeParameter#4556
andrewbranch with Copilot wants to merge 2 commits into
mainfrom
copilot/add-get-constraint-and-get-default

Conversation

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

The TypeParameter API object exposed no direct way to read a type parameter's constraint or default. Reading a constraint required Checker.getConstraintOfTypeParameter(type), and no getter existed for the default at all — inconsistent with SubstitutionType, which already has getConstraint().

// before: only via the checker, no default getter
const constraint = await checker.getConstraintOfTypeParameter(tp);

// now
const constraint = await tp.getConstraint(); // Type | undefined
const def = await tp.getDefault();           // Type | undefined

Changes

  • Client interface (async/types.ts): add getConstraint() and getDefault() to TypeParameter, both returning Type | undefined.
  • Client impl (async/api.ts):
    • TypeObject.getConstraint() dispatches on TypeFlags.TypeParameter — type parameters resolve through the checker endpoint getConstraintOfTypeParameter, while substitution types keep the existing preloaded-handle path.
    • getDefault() calls the new getDefaultFromTypeParameter endpoint.
    • Add fetchCheckerType registry helper for checker-level endpoints keyed by type that resolve to a single optional type (mirrors fetchBaseTypes).
    • Sync API/tests regenerated from the async source.
  • Server (internal/api): register getDefaultFromTypeParameter in proto.go and add handleGetDefaultFromTypeParameter in session.go, delegating to the already-exported checker.GetDefaultFromTypeParameter and returning null when absent.
  • Tests: async/sync coverage for a constrained + defaulted type parameter and one with neither (both getters return undefined).

Notes for review

getConstraint() is kept as a single method that branches on type flags rather than duplicated, preserving SubstitutionType's preloaded-handle behavior while giving type parameters checker-backed resolution.

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>
Copilot AI changed the title [WIP] Add .getConstraint() and .getDefault() getter to TypeParameter Add getConstraint() and getDefault() getters to TypeParameter Jul 7, 2026
Copilot AI requested a review from andrewbranch July 7, 2026 18:18
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.

Add .getConstraint() and .getDefault() getter to TypeParameter

2 participants