params

tcmts.cli.semver_checks.params · #vpp2dmml · term · runs anywhere

import type { Param } from "#codebase/tcmts/cli/semver_checks";
import { declarationOf } from "#codebase/tcmts/core/ts";
import type { TypeChecker } from "#codebase/tcmts/core/ts";
import { isParameterDeclaration as ts_isParameter } from "typescript/ast";
import type { ParameterDeclaration as ts_ParameterDeclaration } from "typescript/ast";
import type { Signature as ts_Signature } from "typescript/sync";

export function params(checker: TypeChecker, s: ts_Signature): Param[] {
  const ps = s.getParameters();
  return ps.map((p, i) => {
    const decl = declarationOf(p) as ts_ParameterDeclaration | undefined;
    return {
      name: p.name,
      type: checker.getTypeOfSymbol(p),
      optional: !!decl && ts_isParameter(decl) && (!!decl.questionToken || !!decl.initializer),
      rest: s.hasRestParameter && i === ps.length - 1,
    };
  });
}

uses

used by