matchShapes

tcmts.core.shape.matchShapes · #m6joauyz · term · runs anywhere

The closest way a definition's type answers a query, if any (over the definition's overloads).

import { matchOne } from "#codebase/tcmts/core/shape";
import type { ShapeMatch, TypeShape } from "#codebase/tcmts/core/shape";

export function matchShapes(query: TypeShape, def: TypeShape): ShapeMatch | undefined {
  let best: ShapeMatch | undefined;
  for (const q of query) for (const d of def) {
    const m = matchOne(q, d);
    if (m && (!best || m.cost < best.cost)) best = m;
  }
  return best;
}

uses

used by