fits

tcmts.cli.semver_checks.fits · #umm4w2cj · term · runs anywhere

Whether every call that fits old fits next too: arguments it takes, a result old callers can use.

import { params } from "#codebase/tcmts/cli/semver_checks";
import type { Param } from "#codebase/tcmts/cli/semver_checks";
import type { TypeChecker } from "#codebase/tcmts/core/ts";
import type { Signature as ts_Signature } from "typescript/sync";

export function fits(checker: TypeChecker, next: ts_Signature, old: ts_Signature): boolean {
  const [x, y] = [params(checker, old), params(checker, next)];
  const required = (ps: Param[]) => ps.filter((p) => !p.optional && !p.rest).length;
  if (required(y) > required(x)) return false;
  if (y.length < x.length && !y.some((p) => p.rest)) return false;
  for (let i = 0; i < Math.min(x.length, y.length); i++) if (!checker.isTypeAssignableTo(x[i]!.type, y[i]!.type)) return false;
  return checker.isTypeAssignableTo(checker.getReturnTypeOfSignature(next), checker.getReturnTypeOfSignature(old));
}

uses

used by