On this page
DocumentationSDK

Safe SDK

calculateSafe returns a Promise of native Effect Result<Report, TaxKitError>. Narrow _tag: "Success" to read success, or _tag: "Failure" to read failure. All expected failures have Schema-tagged identities.

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;
  }
}

Use Schema.Result(definition.outputSchema, TaxKitError) and Schema.toCodecJson to persist outcomes. A closed client returns TaxKitClientDisposedError directly in failure. calculate rejects with the same expected error vocabulary; TypeScript cannot type Promise rejection channels.

Plain SDK owns client lifetime examples.