Skip to content

Commit 24696ef

Browse files
committed
[schema] rename s.null / s.void because typescript produces erroneous declaration files microsoft/TypeScript#62081
1 parent ab2d748 commit 24696ef

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

schema.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class $Schema {
8989
* @type {$Schema<T?>}
9090
*/
9191
get nullable () {
92-
return union(this, null_)
92+
return union(this, $null)
9393
}
9494

9595
/**
@@ -411,7 +411,7 @@ export class $Lambda extends $Schema {
411411
* @param {Args} args
412412
* @return {$Schema<(...args:UnwrapArray<TuplePop<Args>>)=>Unwrap<TupleLast<Args>>>}
413413
*/
414-
export const lambda = (...args) => new $Lambda(args.length > 0 ? args : [void_])
414+
export const lambda = (...args) => new $Lambda(args.length > 0 ? args : [$void])
415415

416416
/**
417417
* @template {Array<$Schema<any>>} T
@@ -505,19 +505,16 @@ export const string = constructedBy(String)
505505
/**
506506
* @type {$Schema<undefined>}
507507
*/
508-
const undefined_ = literal(undefined)
508+
const $undefined = literal(undefined)
509509

510-
/**
511-
* @type {$Schema<void>}
512-
*/
513-
const void_ = undefined_
510+
export { $undefined as undefined }
514511

515512
/**
516-
* @type {$Schema<null>}
513+
* @type {$Schema<void>}
517514
*/
518-
const null_ = literal(null)
515+
export const $void = literal(undefined)
519516

520-
export { null_ as null, void_ as void, undefined_ as undefined }
517+
export const $null = /** @type {$Schema<null>} */ (literal(null))
521518

522519
/* c8 ignore start */
523520
/**

schema.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,31 +204,31 @@ export const testSchemas = _tc => {
204204
s.number.validate(known)
205205
// @ts-expect-error
206206
s.number.validate(unknown)
207-
const f = s.lambda(s.number, s.void).ensure((_x) => {})
207+
const f = s.lambda(s.number, s.$void).ensure((_x) => {})
208208
// should match a function with more parameters
209-
t.assert(s.lambda(s.number, s.string, s.void).validate(f))
209+
t.assert(s.lambda(s.number, s.string, s.$void).validate(f))
210210
// should still not match a different function
211211
// @ts-expect-error
212-
s.lambda(s.string, s.void).validate(f)
213-
const x = s.object({ f: s.lambda(s.string, s.void), n: s.number }).ensure({ f: () => {}, n: 99 })
212+
s.lambda(s.string, s.$void).validate(f)
213+
const x = s.object({ f: s.lambda(s.string, s.$void), n: s.number }).ensure({ f: () => {}, n: 99 })
214214
t.assert(x.n === 99)
215215
s.lambda().cast(() => {})
216216
})
217217
t.group('lambda', () => {
218218
const $fun = s.lambda(s.number, s.string, s.string)
219219
t.assert($fun.validate(() => ''))
220-
t.assert($fun.validate(/** @param {number} n */ (n) => ''))
220+
t.assert($fun.validate(/** @param {number} _n */ (_n) => ''))
221221
// @ts-expect-error
222222
$fun.validate(/** @param {number} n */ (n) => n) // expected string result
223-
const $fun2 = s.lambda(s.number, s.string, s.void)
223+
const $fun2 = s.lambda(s.number, s.string, s.$void)
224224
t.assert($fun2.validate(() => ''))
225225
t.assert($fun2.validate(/** @param {number} n */ (n) => n + ''))
226226
t.assert($fun2.validate(/** @param {number} n */ (n) => n)) // this works now, because void is the absense of value
227227
const $fun3 = s.lambda(s.number, s.undefined)
228228
// @ts-expect-error
229229
$fun3.validate(/** @param {number} n */ (n) => n) // this doesn't work, because expected the literal undefined.
230230
// @ts-expect-error
231-
t.assert(!$fun3.validate(/** @type {(a: number, b: number) => undefined} */ (a, b) => undefined)) // too many parameters
231+
t.assert(!$fun3.validate(/** @type {(a: number, b: number) => undefined} */ (_a, _b) => undefined)) // too many parameters
232232
})
233233
}
234234

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2022",
4-
"lib": ["ES2022", "dom"],
5-
"module": "NodeNext",
3+
"target": "esnext",
4+
"lib": ["dom", "ES2022"],
5+
"module": "nodenext",
66
"allowJs": true,
77
"checkJs": true,
88
"declaration": true,

0 commit comments

Comments
 (0)