-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbug.ts
25 lines (24 loc) · 1.07 KB
/
bug.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
namespace bug {
type ErrorMessage = string;
type AccountCode = string;
type UserName = string;
const validateUserName = (userName: UserName): true | ErrorMessage => {
if (userName.match(/^[a-z]+$/) === null) return `user name must be l/c: [${userName}]`;
return true;
}
const validateAccountCode = (code: AccountCode): true | ErrorMessage => {
if (code.match(/^[AB][0-9]+$/) === null) return `account code not valid: [${code}]`;
return true;
}
export const validateDetails = (userName: UserName, accountCode: AccountCode): void => {
if (userName === '') throw 'user name cannot be blank';
if (accountCode === '') throw 'account code cannot be blank';
let msg = validateAccountCode(accountCode);
if (msg !== true) throw msg;
msg = validateUserName(accountCode);
if (msg !== true) throw msg;
}
export const goodName: UserName = 'bob';
export const goodCode: AccountCode = 'A1234';
validateDetails(goodName, goodCode); // what bug makes this throw an exception ???
}