Skip to content

Commit 5be204e

Browse files
committed
Fix slow types pointed out by JSR
1 parent 007124e commit 5be204e

2 files changed

Lines changed: 26 additions & 11 deletions

File tree

.changeset/quick-dots-tap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@badrap/valita": patch
3+
---
4+
5+
Fix slow types pointed out by JSR

src/index.ts

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,43 +1805,53 @@ const never = singleton<never>(
18051805
/**
18061806
* Create a validator that matches any string value.
18071807
*/
1808-
const string = singleton<string>("string", TAG_STRING, (v) =>
1809-
typeof v === "string" ? undefined : ISSUE_EXPECTED_STRING,
1808+
const string: () => Type<string> = singleton<string>(
1809+
"string",
1810+
TAG_STRING,
1811+
(v) => (typeof v === "string" ? undefined : ISSUE_EXPECTED_STRING),
18101812
);
18111813

18121814
/**
18131815
* Create a validator that matches any number value.
18141816
*/
1815-
const number = singleton<number>("number", TAG_NUMBER, (v) =>
1816-
typeof v === "number" ? undefined : ISSUE_EXPECTED_NUMBER,
1817+
const number: () => Type<number> = singleton<number>(
1818+
"number",
1819+
TAG_NUMBER,
1820+
(v) => (typeof v === "number" ? undefined : ISSUE_EXPECTED_NUMBER),
18171821
);
18181822

18191823
/**
18201824
* Create a validator that matches any bigint value.
18211825
*/
1822-
const bigint = singleton<bigint>("bigint", TAG_BIGINT, (v) =>
1823-
typeof v === "bigint" ? undefined : ISSUE_EXPECTED_BIGINT,
1826+
const bigint: () => Type<bigint> = singleton<bigint>(
1827+
"bigint",
1828+
TAG_BIGINT,
1829+
(v) => (typeof v === "bigint" ? undefined : ISSUE_EXPECTED_BIGINT),
18241830
);
18251831

18261832
/**
18271833
* Create a validator that matches any boolean value.
18281834
*/
1829-
const boolean = singleton<boolean>("boolean", TAG_BOOLEAN, (v) =>
1830-
typeof v === "boolean" ? undefined : ISSUE_EXPECTED_BOOLEAN,
1835+
const boolean: () => Type<boolean> = singleton<boolean>(
1836+
"boolean",
1837+
TAG_BOOLEAN,
1838+
(v) => (typeof v === "boolean" ? undefined : ISSUE_EXPECTED_BOOLEAN),
18311839
);
18321840

18331841
/**
18341842
* Create a validator that matches `null`.
18351843
*/
1836-
const null_ = singleton<null>("null", TAG_NULL, (v) =>
1844+
const null_: () => Type<null> = singleton<null>("null", TAG_NULL, (v) =>
18371845
v === null ? undefined : ISSUE_EXPECTED_NULL,
18381846
);
18391847

18401848
/**
18411849
* Create a validator that matches `undefined`.
18421850
*/
1843-
const undefined_ = singleton<undefined>("undefined", TAG_UNDEFINED, (v) =>
1844-
v === undefined ? undefined : ISSUE_EXPECTED_UNDEFINED,
1851+
const undefined_: () => Type<undefined> = singleton<undefined>(
1852+
"undefined",
1853+
TAG_UNDEFINED,
1854+
(v) => (v === undefined ? undefined : ISSUE_EXPECTED_UNDEFINED),
18451855
);
18461856

18471857
class LiteralType<Out extends Literal = Literal> extends Type<Out> {

0 commit comments

Comments
 (0)