https://github.com/dozro/ts-golike-errors
https://github.com/dozro/ts-golike-errors
Last synced: 4 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/dozro/ts-golike-errors
- Owner: dozro
- License: mpl-2.0
- Created: 2026-06-28T18:31:07.000Z (11 days ago)
- Default Branch: main
- Last Pushed: 2026-06-29T13:33:35.000Z (10 days ago)
- Last Synced: 2026-07-01T01:32:16.351Z (8 days ago)
- Language: TypeScript
- Size: 159 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go-like errors
a foolish approach to error handling utilizing typescript.
## examples
```typescript
const result: Result = {
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
```typescript
type ParseError = {
code: "INVALID_JSON";
message: string;
};
function parseJson(text: string): Result {
try {
return {
success: true,
data: JSON.parse(text),
};
} catch {
return {
success: false,
error: {
code: "INVALID_JSON",
message: "Failed to parse JSON.",
},
};
}
}
```