1.1.3 • Published 4 years ago

@alexshelkov/result v1.1.3

Weekly downloads
110
License
MIT
Repository
github
Last release
4 years ago

Type-safe error handling without exceptions

Flexible and explicit error handling with a small flavor of functional languages.

TypeScript Test Coverage Status

Result type allows you go from this:

const user = getUser(email);

if (!user) {
    throw new Error("Can't get user") // but what happens, why email is invalid? 
                                      // and who will catch this error?
}

to this:

const userResult = getUser(email);

if (userResult.isErr()) {
  const err = userResult.err();
  
  switch (err.type) {
    case 'InvalidEmail':
      console.log('User email is invalid'); break;
    case 'UserNotExists':
      console.log("Can't find the user"); break;
    case 'UserBannded':
      console.log(`User was bannded: ${err.ban}`); break;
  }
}
1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago