-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix an incorrect return on certain pipes with validated output (#974)
- Loading branch information
1 parent
cd6cff2
commit 52be860
Showing
12 changed files
with
153 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@arktype/schema": patch | ||
--- | ||
|
||
Pipe and narrow bug fixes (see [arktype CHANGELOG](../type/CHANGELOG.md)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,18 @@ | ||
import { type } from "arktype" | ||
|
||
const parseBigint = type("string", "=>", (s, ctx) => { | ||
try { | ||
return BigInt(s) | ||
} catch { | ||
return ctx.error("a valid number") | ||
} | ||
const user = type({ | ||
name: "string", | ||
age: "number" | ||
}) | ||
|
||
// or | ||
const parseUser = type("string").pipe(s => JSON.parse(s), user) | ||
|
||
const parseBigint2 = type("string").pipe((s, ctx) => { | ||
try { | ||
return BigInt(s) | ||
} catch { | ||
return ctx.error("a valid number") | ||
} | ||
}) | ||
|
||
const Test = type({ | ||
group: { | ||
nested: { | ||
value: parseBigint | ||
} | ||
} | ||
}) | ||
const validUser = parseUser(`{ "name": "David", "age": 30 }`) //? | ||
// ^? | ||
|
||
const myFunc = () => { | ||
const out = Test({}) | ||
if (out instanceof type.errors) return | ||
const invalidUser = parseUser(`{ "name": "David" }`) | ||
// ^? | ||
|
||
const value: bigint = out.group.nested.value | ||
if (invalidUser instanceof type.errors) { | ||
console.log(invalidUser.summary) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters