Skip to content

Add batched assignability checks into the Checker API #63873

Description

Proposal

// existing
isTypeAssignableTo(source: Type, target: Type): boolean;

// batched - one result per pair, in order
areTypesAssignableTo(pairs: readonly (readonly [source: Type, target: Type])[]): boolean[];

// sugar for the two common shapes
areTypesAssignableTo(sources: readonly Type[], target: Type): boolean[];
areTypesAssignableTo(source: Type, targets: readonly Type[]): boolean[];

// short-circuiting quantifiers - one boolean, server stops early
isAnyTypeAssignableTo(sources: readonly Type[], target: Type): boolean;
areAllTypesAssignableTo(sources: readonly Type[], target: Type): boolean;

isTypeAssignableTo answers one pair per call, but in my use-case I usually have more than one pair to check.

What I actually do is match a type against a list of candidate types and take the ones that fit,
so a single run is candidates × requests checks. In my case - there could be thousands of such checks.

The API already batches like this in other places, getSymbolAtPosition, getSymbolAtLocation, getTypeAtLocation and getTypeOfSymbol all take arrays.

The short-circuiting quantifiers are also nice to have, but I understand that it complicates an api and I'm not sure it's really worth to have them since checker is already blazingly fast 😄

I've also prototyped the whole thing locally (Apple M4 Max, macOS 26.5.2, node v24.11.1, main@322fa1ecd):
1000 pairs cost 8.8 ms as 1000 sync calls versus 0.17 ms in one batched call, and 55 ms versus 0.24 ms on the async API.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions