On this page
DocumentationSDK

Plain SDK

Call a complete calculator definition with a checked scenario. The selected definition infers the report.

TypeScript
import { calculate } from "taxkit";
import { AuAnnualIncomeTaxCalculation } from "taxkit/au";
import { AnnualTaxScenarioInputSchema } from "taxkit/au/schemas";
import { Cents, Money, NonNegativeMoney } from "taxkit/money";

const taxableIncome = NonNegativeMoney.make(
  Money.fromCents(Cents.make(9_000_000))
);
const input = AnnualTaxScenarioInputSchema.make({ taxableIncome });
const report = await calculate(AuAnnualIncomeTaxCalculation, input);
report.liability.cents;

For input from users, parse exact decimal text with native Result before constructing the scenario.

TypeScript
import { calculateSafe } from "taxkit";
import { AuPayTakeHomeCalculation } from "taxkit/au";
import { TakeHomeScenarioInputSchema } from "taxkit/au/schemas";
import { fromDecimal, nonNegative } from "taxkit/money";
import { Result } from "effect";

const input = Result.gen(function* () {
  const grossPay = yield* fromDecimal("1654.00").pipe(
    Result.flatMap(nonNegative)
  );
  return TakeHomeScenarioInputSchema.make({
    grossPay,
    period: "weekly",
    taxFreeThresholdClaimed: true,
  });
});
if (Result.isSuccess(input)) {
  const result = await calculateSafe(AuPayTakeHomeCalculation, input.success);
  if (Result.isSuccess(result)) {
    result.success.netPay.cents;
  } else {
    result.failure._tag;
  }
}

createClient() owns a reusable lazy lifetime. Call client.calculate(definition, input) or client.calculateSafe(definition, input) and await client.dispose() or use await using client = createClient(). Closing interrupts pending work and waits for finalisers. One-shot helpers clean up before settling.

See Safe SDK and Effect SDK.