
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@vladbasin/ts-result
Advanced tools
This library brings elements of functional programming to TypeScript/JavaScript. See Use cases section for details.
npm install @vladbasin/ts-result
yarn add @vladbasin/ts-result
Let's assume you have to work with the set of async methods, which load data from backend and return Promise. Normally you use try\catch, async\await, then\catch, if\then\else to handle results. Readability isn't really good with this approach.
showLoader();
try {
const wallet = await getWalletAsync();
if (wallet.money < 10) {
alert("Not enough money");
return;
}
const item = await getItemAsync();
const response = await purchaseAsync(item);
if (!response.success) {
alert(response.error);
return;
}
log("Purchase success");
}
catch (error) {
alert(error);
}
finally {
hideLoader();
}
However, with this library instead you can write nice readable chains of methods:
import { Result } from "@vladbasin/ts-result";
showLoader();
Result
.FromPromise(getWalletAsync())
.ensure(wallet => wallet.money > 10, "Not enough money")
.onSuccess(() => getItemAsync(itemId))
.onSuccess(item => purchaseAsync(item))
.ensure(response => response.success, response.error)
.onFailure(error => alert(error))
.onSuccess(() => log("Purchase success"))
.onBoth(result => hideLoader())
.run();
Without this library (poor readability, code repeats)
const usernameValidation = validateUsername(username);
if (!usernameValidation.success) {
alert(usernameValidation.error)
return;
}
const passwordValidation = validatePassword(password);
if (!passwordValidation.success) {
alert(passwordValidation.error)
return;
}
const passwordRepeatValidation = validatePasswordRepeat(passwordRepeat, password);
if (!passwordRepeatValidation.success) {
alert(passwordRepeatValidation.error)
return;
}
With this library (readable code, reusable logic)
import { Result } from "@vladbasin/ts-result";
Result
.Start()
.onSuccess(() => validateUsername(username))
.onSuccess(() => validatePassword(password))
.onSuccess(() => validatePasswordRepeat(passwordRepeat, password))
.onFailure(error => alert(error))
.run();
This library also provides API to retry(), delay(), and combine() asynchonous code. See inline comments for more documentation
FAQs
Wrapper around promise for functional programming
We found that @vladbasin/ts-result demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.