From afa7d16d3426816fbe33159d6cbcc89aa3c71d16 Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Thu, 19 Oct 2023 16:30:33 +0800 Subject: [PATCH 1/3] use packaged-installed tsc --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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", From 6b08e6b97da5a4fa927fe0f215899918efef12bb Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Thu, 19 Oct 2023 16:28:47 +0800 Subject: [PATCH 2/3] wrong return type --- src/result.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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. From f87f56b6084a478cf66e896fbdbc46c5ae3948da Mon Sep 17 00:00:00 2001 From: Paul Rouget Date: Thu, 19 Oct 2023 14:51:10 +0800 Subject: [PATCH 3/3] Implement Option.or --- src/option.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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; } }