Slide 18
Slide 18 text
設計・実装
直和型で不正な状態を回避する
OK
NG
type InvitedAccount = {
id: AccountId;
status: 'pending';
token: InvitationToken;
};
type ActivatedAccount = {
id: AccountId;
status: 'active';
};
type Account =
InvitedAccount | ActivatedAccount;
type Account = {
id: AccountId;
status: 'pending' | 'active';
token?: InvitationToken;
};
© atama plus Inc.
// 不正なあり得ない状態を表現できてしまう
const account: Account = {
id, status: 'pending',
};
18