Skip to content

Commit 0b1acde

Browse files
authored
Merge pull request #474 from traversable/fix-typebox-transitive-deps
fix(typebox,typebox-types): Property '[Kind]' is missing in type 'TSchema'
2 parents 99a5e14 + b87aac2 commit 0b1acde

File tree

3 files changed

+60
-53
lines changed

3 files changed

+60
-53
lines changed

.changeset/funny-lamps-add.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@traversable/typebox-types": patch
3+
"@traversable/typebox": patch
4+
---
5+
6+
fix(typebox,typebox-types): fixes transitive dep bug, `Property '[Kind]' is missing in type 'TSchema'` TypeError

packages/typebox-types/src/functor.ts

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import * as typebox from '@sinclair/typebox'
1+
import * as T from '@sinclair/typebox'
22
import {
33
PatternNeverExact,
44
PatternNumberExact,
55
PatternStringExact,
66
} from '@sinclair/typebox/type'
7-
import type * as T from '@traversable/registry'
7+
import type * as t from '@traversable/registry'
8+
import type { Kind, HKT } from '@traversable/registry'
89
import { accessor, fn, has, omit, Object_keys } from '@traversable/registry'
910

1011
export interface Index {
@@ -14,7 +15,7 @@ export interface Index {
1415
varName?: string
1516
}
1617

17-
export type CompilerAlgebra<T> = { (src: T.Kind<Type.Free, T>, ix: CompilerIndex, input: any): T }
18+
export type CompilerAlgebra<T> = { (src: Kind<Type.Free, T>, ix: CompilerIndex, input: any): T }
1819
export interface CompilerIndex extends Omit<Index, 'path'> {
1920
dataPath: (string | number)[]
2021
isOptional: boolean
@@ -37,22 +38,22 @@ export const defaultCompilerIndex = {
3738
} satisfies CompilerIndex
3839

3940
export const isNullary = (x: unknown): x is Type.Nullary =>
40-
(!!x && typeof x === 'object' && typebox.Kind in x)
41+
(!!x && typeof x === 'object' && T.Kind in x)
4142
&& (
42-
x[typebox.Kind] === 'Never'
43-
|| x[typebox.Kind] === 'Any'
44-
|| x[typebox.Kind] === 'Unknown'
45-
|| x[typebox.Kind] === 'Void'
46-
|| x[typebox.Kind] === 'Null'
47-
|| x[typebox.Kind] === 'Undefined'
48-
|| x[typebox.Kind] === 'Symbol'
49-
|| x[typebox.Kind] === 'Boolean'
50-
|| x[typebox.Kind] === 'Integer'
51-
|| x[typebox.Kind] === 'BigInt'
52-
|| x[typebox.Kind] === 'Number'
53-
|| x[typebox.Kind] === 'String'
54-
|| x[typebox.Kind] === 'Literal'
55-
|| x[typebox.Kind] === 'Date'
43+
x[T.Kind] === 'Never'
44+
|| x[T.Kind] === 'Any'
45+
|| x[T.Kind] === 'Unknown'
46+
|| x[T.Kind] === 'Void'
47+
|| x[T.Kind] === 'Null'
48+
|| x[T.Kind] === 'Undefined'
49+
|| x[T.Kind] === 'Symbol'
50+
|| x[T.Kind] === 'Boolean'
51+
|| x[T.Kind] === 'Integer'
52+
|| x[T.Kind] === 'BigInt'
53+
|| x[T.Kind] === 'Number'
54+
|| x[T.Kind] === 'String'
55+
|| x[T.Kind] === 'Literal'
56+
|| x[T.Kind] === 'Date'
5657
)
5758

5859
export type TypeName = typeof TypeName[keyof typeof TypeName]
@@ -89,47 +90,47 @@ export function tagged<Name extends keyof typeof TypeName>(typeName: Name) {
8990
(typeName === TypeName.allOf && TypeName.allOf in x)
9091
|| (typeName === TypeName.anyOf && TypeName.anyOf in x)
9192
|| (
92-
typebox.Kind in x && x[typebox.Kind] === TypeName[typeName]
93+
T.Kind in x && x[T.Kind] === TypeName[typeName]
9394
)
9495
)
9596
}
9697

9798
function internalIsOptional(x: unknown): boolean {
98-
return !!x && typeof x === 'object' && typebox.OptionalKind in x
99+
return !!x && typeof x === 'object' && T.OptionalKind in x
99100
}
100101

101102
export function isOptional<T>(x: unknown): x is Type.Optional<T> {
102-
return (!!x && typeof x === 'object' && typebox.Kind in x && x[typebox.Kind] === TypeName.optional)
103+
return (!!x && typeof x === 'object' && T.Kind in x && x[T.Kind] === TypeName.optional)
103104
}
104105

105106
export declare namespace Type {
106-
interface Never { [typebox.Kind]: 'Never' }
107-
interface Any { [typebox.Kind]: 'Any' }
108-
interface Unknown { [typebox.Kind]: 'Unknown' }
109-
interface Void { [typebox.Kind]: 'Void' }
110-
interface Null { [typebox.Kind]: 'Null' }
111-
interface Undefined { [typebox.Kind]: 'Undefined' }
112-
interface Symbol { [typebox.Kind]: 'Symbol' }
113-
interface Boolean { [typebox.Kind]: 'Boolean' }
114-
interface Date { [typebox.Kind]: 'Date' }
115-
interface Literal { [typebox.Kind]: 'Literal', const: string | number | boolean }
116-
interface Integer extends Integer.Bounds { [typebox.Kind]: 'Integer' }
107+
interface Never { [T.Kind]: 'Never' }
108+
interface Any { [T.Kind]: 'Any' }
109+
interface Unknown { [T.Kind]: 'Unknown' }
110+
interface Void { [T.Kind]: 'Void' }
111+
interface Null { [T.Kind]: 'Null' }
112+
interface Undefined { [T.Kind]: 'Undefined' }
113+
interface Symbol { [T.Kind]: 'Symbol' }
114+
interface Boolean { [T.Kind]: 'Boolean' }
115+
interface Date { [T.Kind]: 'Date' }
116+
interface Literal { [T.Kind]: 'Literal', const: string | number | boolean }
117+
interface Integer extends Integer.Bounds { [T.Kind]: 'Integer' }
117118
namespace Integer { interface Bounds { minimum?: number, maximum?: number, multipleOf?: number } }
118-
interface BigInt extends BigInt.Bounds { [typebox.Kind]: 'BigInt' }
119+
interface BigInt extends BigInt.Bounds { [T.Kind]: 'BigInt' }
119120
namespace BigInt { interface Bounds { minimum?: bigint, maximum?: bigint, multipleOf?: bigint } }
120-
interface Number extends Number.Bounds { [typebox.Kind]: 'Number' }
121+
interface Number extends Number.Bounds { [T.Kind]: 'Number' }
121122
namespace Number { interface Bounds { exclusiveMinimum?: number, exclusiveMaximum?: number, minimum?: number, maximum?: number, multipleOf?: number } }
122-
interface String extends String.Bounds { [typebox.Kind]: 'String' }
123+
interface String extends String.Bounds { [T.Kind]: 'String' }
123124
namespace String { interface Bounds { minLength?: number, maxLength?: number } }
124-
interface Array<S> extends Array.Bounds { [typebox.Kind]: 'Array', items: S }
125+
interface Array<S> extends Array.Bounds { [T.Kind]: 'Array', items: S }
125126
namespace Array { interface Bounds { minItems?: number, maxItems?: number } }
126-
interface Optional<S> { [typebox.Kind]: 'Optional', schema: S }
127-
interface Record<S> { [typebox.Kind]: 'Record', patternProperties: Record.PatternProperties<S> }
127+
interface Optional<S> { [T.Kind]: 'Optional', schema: S }
128+
interface Record<S> { [T.Kind]: 'Record', patternProperties: Record.PatternProperties<S> }
128129
namespace Record { type PatternProperties<S> = { [PatternStringExact]: S, [PatternNumberExact]: S, [PatternNeverExact]: S } }
129-
interface Tuple<S> { [typebox.Kind]: 'Tuple', items: S[] }
130-
interface Object<S> { [typebox.Kind]: 'Object', properties: { [x: string]: S }, required: string[] }
131-
interface Union<S> { [typebox.Kind]: 'Union', anyOf: S[] }
132-
interface Intersect<S> { [typebox.Kind]: 'Intersect', allOf: S[] }
130+
interface Tuple<S> { [T.Kind]: 'Tuple', items: S[] }
131+
interface Object<S> { [T.Kind]: 'Object', properties: { [x: string]: S }, required: string[] }
132+
interface Union<S> { [T.Kind]: 'Union', anyOf: S[] }
133+
interface Intersect<S> { [T.Kind]: 'Intersect', allOf: S[] }
133134
type Nullary =
134135
| Type.Never
135136
| Type.Any
@@ -155,7 +156,7 @@ export declare namespace Type {
155156
| Type.Intersect<S>
156157
| Type.Object<S>
157158

158-
interface Free extends T.HKT { [-1]: F<this[0]> }
159+
interface Free extends HKT { [-1]: F<this[0]> }
159160
type F<S> = Type.Nullary | Type.Unary<S>
160161
type Fixpoint =
161162
| Type.Nullary
@@ -192,7 +193,7 @@ export declare namespace Type {
192193
}
193194
}
194195

195-
export const Functor: T.Functor.Ix<Index, Type.Free> = {
196+
export const Functor: t.Functor.Ix<Index, Type.Free> = {
196197
map(f) {
197198
return (x) => {
198199
switch (true) {
@@ -228,7 +229,7 @@ export const Functor: T.Functor.Ix<Index, Type.Free> = {
228229
}
229230
}
230231

231-
export const CompilerFunctor: T.Functor.Ix<CompilerIndex, Type.Free> = {
232+
export const CompilerFunctor: t.Functor.Ix<CompilerIndex, Type.Free> = {
232233
map(f) {
233234
return (x) => {
234235
switch (true) {
@@ -298,11 +299,11 @@ const internalFold = fn.catamorphism(Functor, defaultIndex)
298299

299300
export type Algebra<T> = {
300301
(src: Type.F<T>, ix?: Index): T
301-
(src: typebox.TSchema, ix?: Index): T
302+
(src: Partial<T.TSchema>, ix?: Index): T
302303
(src: Type.F<T>, ix?: Index): T
303304
}
304305

305-
export type Fold = <T>(g: (src: Type.F<T>, ix: Index, x: typebox.TSchema) => T) => Algebra<T>
306+
export type Fold = <T>(g: (src: Type.F<T>, ix: Index, x: T.TSchema) => T) => Algebra<T>
306307

307308
export const fold
308309
: Fold
@@ -313,8 +314,8 @@ const preprocess
313314
= <never>internalFold((schema) => {
314315
if (!internalIsOptional(schema)) return schema
315316
else {
316-
const withoutKind = omit(schema, [typebox.OptionalKind])
317-
return { [typebox.Kind]: TypeName.optional, schema: withoutKind }
317+
const withoutKind = omit(schema, [T.OptionalKind])
318+
return { [T.Kind]: TypeName.optional, schema: withoutKind }
318319
}
319320
})
320321

packages/typebox/src/deep-equal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const writeableDefaults = {
9696
function optional(
9797
x: F.Type.Optional<Builder>,
9898
ix: F.Index,
99-
input: T.TSchema
99+
input: Partial<T.TSchema>
100100
): Builder {
101101
if (!F.tagged('optional')(input)) {
102102
return Invariant.IllegalState('deepEqual', 'expected input to be a union schema', input)
@@ -167,7 +167,7 @@ function record(
167167
function union(
168168
x: Type.Union<Builder>,
169169
_: F.Index,
170-
input: T.TSchema
170+
input: Partial<T.TSchema>
171171
): Builder {
172172
if (!F.tagged('anyOf')<T.TSchema>(input)) {
173173
return Invariant.IllegalState('deepEqual', 'expected input to be a union schema', input)
@@ -218,7 +218,7 @@ function intersect(
218218
function tuple(
219219
x: F.Type.Tuple<Builder>,
220220
ix: F.Index,
221-
input: T.TSchema
221+
input: Partial<T.TSchema>
222222
): Builder {
223223
if (!F.tagged('tuple')<T.TSchema>(input)) {
224224
return Invariant.IllegalState('deepEqual', `expected input to be a tuple schema`, input)
@@ -244,7 +244,7 @@ function tuple(
244244
function object(
245245
x: F.Type.Object<Builder>,
246246
ix: F.Index,
247-
input: T.TSchema
247+
input: Partial<T.TSchema>
248248
): Builder {
249249
if (!F.tagged('object')<T.TSchema>(input)) {
250250
return Invariant.IllegalState('deepEqual', 'expected input to be an object schema', input)

0 commit comments

Comments
 (0)