Package Exports
- @1ry/golike-errors
- @1ry/golike-errors/lib/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@1ry/golike-errors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Go-like errors
a foolish approach to error handling utilizing typescript.
examples
const result: Result<number, string> = {
success: true,
data: 42,
};
if (result.success) {
// result is { success: true; data: number }
console.log(result.data);
} else {
// result is { success: false; error: string }
console.error(result.error);
}or
type ParseError = {
code: "INVALID_JSON";
message: string;
};
function parseJson(text: string): Result<unknown, ParseError> {
try {
return {
success: true,
data: JSON.parse(text),
};
} catch {
return {
success: false,
error: {
code: "INVALID_JSON",
message: "Failed to parse JSON.",
},
};
}
}