On this page
DocumentationSDK

Type safety

One owning calculator definition ties its identity and context to the scenario codec, report codec, expected errors and native executor. Scenarios and facts are nominal: a predeclared object for another calculator cannot widen the selected input type.

TypeScript
import { Effect, Schema } from "effect";
import { AuPayTakeHomeCalculation } from "taxkit/au";
import { calculateReport, decodeInput } from "taxkit/effect";

// Decode the selected scenario once; surplus fields fail as well.
export const invalidInput = decodeInput(AuPayTakeHomeCalculation, {
  taxableIncome: 9_000_000,
});
export const validInput = Schema.decodeEffect(
  Schema.fromJsonString(Schema.Unknown)
)(
  '{"grossPay":{"_tag":"Money","cents":165400,"currency":"AUD"},"period":"weekly","taxFreeThresholdClaimed":true}'
).pipe(
  Effect.flatMap((input) => decodeInput(AuPayTakeHomeCalculation, input)),
  Effect.flatMap((input) => calculateReport(AuPayTakeHomeCalculation, input))
);

Raw numbers cannot stand in for Money. Signed Money requires a non-negative refinement for scenario inputs. A pay scenario supplies one supported period for its amounts. The sacrifice-aware scenario requires salarySacrifice; its definition is AuPayTakeHomeWithSacrificeCalculation. Native rule composition retains distinct GrossPay and TaxablePay identities and unprovided facts in its requirement channel.

Runtime validation

TypeScript
import { Effect } from "effect";
import { AuPayTakeHomeCalculation } from "taxkit/au";
import { calculateReport, decodeInput } from "taxkit/effect";

// Decode the selected scenario once; surplus fields fail as well.
export const invalidInput = decodeInput(AuPayTakeHomeCalculation, {
  taxableIncome: { _tag: "Money", cents: 9_000_000, currency: "AUD" },
});
export const validInput = decodeInput(AuPayTakeHomeCalculation, {
  grossPay: { _tag: "Money", cents: 165_400, currency: "AUD" },
  period: "weekly",
  taxFreeThresholdClaimed: true,
}).pipe(
  Effect.flatMap((input) => calculateReport(AuPayTakeHomeCalculation, input))
);

TypeScript checks relationships and required properties. Runtime Schemas check numeric ranges, exact decimals, extra keys and accounting relationships. A number variable such as 1.5 is rejected by the checked cents constructor at runtime.