separate types

This commit is contained in:
Oli Sturm
2026-04-24 18:15:22 +01:00
parent b1ac745d70
commit d0c9466170
13 changed files with 178 additions and 221 deletions
+53
View File
@@ -0,0 +1,53 @@
import { Result } from '../library/result.js';
import { Money } from './money.js';
export type Account = {
id: string;
balance: Money;
};
export type OpeningBalanceMustBeNonNegative = {
type: 'OpeningBalanceMustBeNonNegative';
};
export type AmountMustBePositive = {
type: 'AmountMustBePositive';
};
export type InsufficientBalance = {
type: 'InsufficientBalance';
balance: Money;
amount: Money;
};
export type AccountNotFound = {
type: 'AccountNotFound';
accountId: string;
};
export type AccountError =
| OpeningBalanceMustBeNonNegative
| AmountMustBePositive
| InsufficientBalance
| AccountNotFound;
export declare const openingBalanceMustBeNonNegative: OpeningBalanceMustBeNonNegative;
export declare const amountMustBePositive: AmountMustBePositive;
export declare const insufficientBalance: (
balance: Money,
amount: Money
) => InsufficientBalance;
export declare const accountNotFound: (accountId: string) => AccountNotFound;
export declare const openAccount: (
id: string,
openingBalance: Money
) => Result<Account, AccountError>;
export declare const withdraw: (
account: Account,
amount: Money
) => Result<Account, AccountError>;