diff --git a/package.json b/package.json
index a98fb08..6577984 100644
--- a/package.json
+++ b/package.json
@@ -40,6 +40,7 @@
"format": "prettier '**/*' -u -w",
"prepack": "yarn test && yarn build",
"test": "vitest run",
+ "test:typecheck": "tsc --noEmit -p tsconfig.test.json",
"typecheck": "tsc --noEmit",
"benchmark": "node benchmark/src/option && node benchmark/src/result && node benchmark/src/future && node benchmark/src/future-result"
},
diff --git a/src/OptionResult.ts b/src/OptionResult.ts
index d1c910d..8ed321b 100644
--- a/src/OptionResult.ts
+++ b/src/OptionResult.ts
@@ -421,7 +421,7 @@ class __Result {
return false;
};
- static fromJSON = (value: JsonResult) => {
+ static fromJSON = (value: JsonResult): Result => {
return value.tag === "Ok"
? Result.Ok(value.value)
: Result.Error(value.error);
diff --git a/test/AsyncData.test.ts b/test/AsyncData.test.ts
index 574ec69..0426746 100644
--- a/test/AsyncData.test.ts
+++ b/test/AsyncData.test.ts
@@ -380,3 +380,12 @@ test("AsyncData isAsyncData", async () => {
expect(AsyncData.isAsyncData([])).toEqual(false);
expect(AsyncData.isAsyncData({})).toEqual(false);
});
+
+test("AsyncData JSON serialization", () => {
+ const data = AsyncData.Loading();
+ expect(
+ AsyncData.fromJSON(data.toJSON()).tap(() => {
+ // use async data
+ }),
+ ).toEqual(data);
+});
diff --git a/test/Future.test.ts b/test/Future.test.ts
index b138f25..e79b109 100644
--- a/test/Future.test.ts
+++ b/test/Future.test.ts
@@ -464,7 +464,7 @@ test("Future concurrent", async () => {
--parallel;
}),
() =>
- Future.make<4>((resolve) => {
+ Future.make((resolve) => {
expect(++parallel).toBeLessThanOrEqual(2);
setTimeout(() => resolve(undefined), 75);
})
diff --git a/test/Option.test.ts b/test/Option.test.ts
index 5e65df1..14488cf 100644
--- a/test/Option.test.ts
+++ b/test/Option.test.ts
@@ -202,3 +202,12 @@ test("Option.isOption", async () => {
expect(Option.isOption([])).toEqual(false);
expect(Option.isOption({})).toEqual(false);
});
+
+test("Option JSON serialization", () => {
+ const option = Option.None();
+ expect(
+ Option.fromJSON(option.toJSON()).tap(() => {
+ // Use option
+ }),
+ ).toEqual(option);
+});
diff --git a/test/Result.test.ts b/test/Result.test.ts
index 3bb3f93..90b4f80 100644
--- a/test/Result.test.ts
+++ b/test/Result.test.ts
@@ -253,3 +253,19 @@ test("Result.isResult", async () => {
expect(Result.isResult([])).toEqual(false);
expect(Result.isResult({})).toEqual(false);
});
+
+test("Result JSON serialization", async () => {
+ const resultOk = Result.Ok({ thing: "hello" });
+ expect(
+ Result.fromJSON(resultOk.toJSON()).tap(() => {
+ // Use result
+ }),
+ ).toEqual(resultOk);
+
+ const resultError = Result.Error(new Error("Oops"));
+ expect(
+ Result.fromJSON(resultError.toJSON()).tap(() => {
+ // Use result
+ }),
+ ).toEqual(resultError);
+});
diff --git a/tsconfig.test.json b/tsconfig.test.json
new file mode 100644
index 0000000..2b1ab51
--- /dev/null
+++ b/tsconfig.test.json
@@ -0,0 +1,9 @@
+{
+ "extends": "./tsconfig.json",
+ "include": ["**/*.test.ts"],
+ "exclude": ["node_modules", "dist"],
+ "compilerOptions": {
+ "noEmit": true,
+ "skipLibCheck": true
+ },
+}