diff --git a/package.json b/package.json index a3cf7fd..eb70c25 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "private": true, "scripts": { "build": "npm run clean && npm run build:ts && npm run build:copy", - "build:ts": "tsc -p tsconfig.json && tsc -p tsconfig.json -m esnext --outDir dist/esm/ -d false -declarationMap false", + "build:ts": "npx tsc -p tsconfig.json && npx tsc -p tsconfig.json -m esnext --outDir dist/esm/ -d false -declarationMap false", "build:copy": "copyfiles README.md LICENSE src/package.json dist --flat && copyfiles src/rxjs-operators/package.json dist --up 1", "clean": "rm -rf dist", "test": "jest", diff --git a/src/option.ts b/src/option.ts index 5786302..941b0e7 100644 --- a/src/option.ts +++ b/src/option.ts @@ -78,6 +78,10 @@ class NoneImpl implements BaseOption { return this; } + or(other: Option): Option { + return other; + } + andThen(op: unknown): None { return this; } @@ -151,6 +155,10 @@ class SomeImpl implements BaseOption { return mapper(this.val); } + or(other: Option): Option { + return this; + } + toResult(error: E): Ok { return Ok(this.val); } @@ -213,7 +221,7 @@ export namespace Option { if (option.some) { return option as Some[number]>; } else { - return option as None; + continue; } } diff --git a/src/result.ts b/src/result.ts index c660515..5e4c25b 100644 --- a/src/result.ts +++ b/src/result.ts @@ -26,11 +26,11 @@ interface BaseResult extends Iterable ? U : ne expect(msg: string): T; /** - * Returns the contained `Ok` value, if does not exist. Throws an error if it does. + * Returns the contained `Err` value, if does not exist. Throws an error if it does. * @param msg the message to throw if Ok value. */ - expectErr(msg: string): T; - + expectErr(msg: string): E; + /** * Returns the contained `Ok` value. * Because this function may throw, its use is generally discouraged.