Skip to content

Commit

Permalink
Fix ts types for assert and fail methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh committed Aug 3, 2024
1 parent 2d71949 commit b6b0137
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion RescriptSchema.gen.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export type S_t<Output, Input = unknown> = {
serialize(value: Output): Result<Input>;
serializeOrThrow(value: Output): Input;
serializeToJsonOrThrow(value: Output): Json;
assert(data: unknown): asserts data is Output;
assert(data: unknown): asserts data is Input;
};

export abstract class S_Path_t {
Expand Down
4 changes: 2 additions & 2 deletions docs/js-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ let nodeSchema = S.recursive<Node>((nodeSchema) =>
```ts
const shortStringSchema = S.refine(S.string, (value, s) =>
if (value.length > 255) {
throw s.fail("String can't be more than 255 characters")
s.fail("String can't be more than 255 characters")
}
)
```
Expand Down Expand Up @@ -555,7 +555,7 @@ const intToString = (schema) =>
(string, s) => {
const int = parseInt(string, 10);
if (isNaN(int)) {
throw s.fail("Can't convert string to int");
s.fail("Can't convert string to int");
}
return int;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tests/src/core/S_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ test("Fails to parse with transform with user error", (t) => {
const schema = S.transform(S.string, (string, s) => {
const number = Number(string);
if (Number.isNaN(number)) {
throw s.fail("Invalid number");
s.fail("Invalid number");
}
return number;
});
Expand Down
2 changes: 1 addition & 1 deletion src/S.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { Json, Result, S_error as Error } from "../RescriptSchema.gen";

export type EffectCtx<Output, Input> = {
schema: Schema<Output, Input>;
fail: (message: string) => void;
fail: (message: string) => never;
};

export type Schema<Output, Input = Output> = S_t<Output, Input>;
Expand Down

0 comments on commit b6b0137

Please sign in to comment.