Scaffold ESM TypeScript rewrite as @larvit/smpp

This commit is contained in:
2026-08-25 16:02:27 +02:00
commit 16c935bb18
16 changed files with 2143 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import type { Result } from '../src/result.ts';
function parse(input: string): Result<{ value: number }> {
const value = Number(input);
if (Number.isNaN(value)) return { err: new Error('not a number') };
return { value };
}
test('destructuring a result narrows on err', () => {
const { err, value } = parse('42');
if (err) {
assert.fail('should have parsed');
}
// Fails to compile if narrowing does not remove undefined from value.
assert.equal(value.toFixed(0), '42');
});
test('a failed result carries err and nothing else', () => {
const { err, value } = parse('nope');
assert.ok(err instanceof Error);
assert.equal(value, undefined);
});