Skip to content

Commit bf4391f

Browse files
authored
Revision 0.34.20 (#1167)
* Disable Computed Types on Record * Version * ChangeLog
1 parent de43700 commit bf4391f

File tree

9 files changed

+63
-73
lines changed

9 files changed

+63
-73
lines changed

changelog/0.34.0.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
### 0.34.0
2+
- [Revision 0.34.20](https://github.com/sinclairzx81/typebox/pull/1167)
3+
- Hotfix: Disable Computed Types on Record
4+
- [Revision 0.34.19](https://github.com/sinclairzx81/typebox/pull/1166)
5+
- Hotfix: Republished due to NPM error
26
- [Revision 0.34.18](https://github.com/sinclairzx81/typebox/pull/1164)
37
- Hotfix: Internal Remap Imports
48
- [Revision 0.34.17](https://github.com/sinclairzx81/typebox/pull/1162)

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sinclair/typebox",
3-
"version": "0.34.19",
3+
"version": "0.34.20",
44
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
55
"keywords": [
66
"typescript",

src/type/record/record.ts

-8
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ import type { Static } from '../static/index'
3333
import type { Evaluate, Ensure, Assert } from '../helpers/index'
3434
import { type TAny } from '../any/index'
3535
import { type TBoolean } from '../boolean/index'
36-
import { type TComputed, Computed } from '../computed/index'
3736
import { type TEnumRecord, type TEnum } from '../enum/index'
3837
import { type TInteger } from '../integer/index'
3938
import { type TLiteral, type TLiteralValue } from '../literal/index'
4039
import { type TNever, Never } from '../never/index'
4140
import { type TNumber, Number } from '../number/index'
4241
import { type TObject, type TProperties, type TAdditionalProperties, type ObjectOptions, Object } from '../object/index'
43-
import { type TRef, Ref } from '../ref/index'
4442
import { type TRegExp } from '../regexp/index'
4543
import { type TString, String } from '../string/index'
4644
import { type TUnion, Union } from '../union/index'
@@ -233,9 +231,6 @@ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = T
233231
// ------------------------------------------------------------------
234232
// prettier-ignore
235233
export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (
236-
Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> :
237-
Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> :
238-
Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> :
239234
Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> :
240235
Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : // (Special: Ensure resolve Enum before Union)
241236
Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> :
@@ -256,9 +251,6 @@ export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (
256251
export function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options: ObjectOptions = {}): TRecordOrObject<Key, Type> {
257252
// prettier-ignore
258253
return (
259-
IsComputed(type) ? Computed('Record', [key, Computed(type.target, type.parameters)], options) :
260-
IsComputed(key) ? Computed('Record', [Computed(type.target, type.parameters), type], options) :
261-
IsRef(key) ? Computed('Record', [Ref(key.$ref), type]) :
262254
IsUnion(key) ? FromUnionKey(key.anyOf, type, options) :
263255
IsTemplateLiteral(key) ? FromTemplateLiteralKey(key, type, options) :
264256
IsLiteral(key) ? FromLiteralKey(key.const, type, options) :

test/runtime/type/guard/kind/computed.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@ describe('guard/kind/TComputed', () => {
1818
const T = Type.Record(Type.String(), Type.String())
1919
Assert.IsTrue(KindGuard.IsRecord(T))
2020
})
21-
// TRecord<TRecordKey, TRef<...>> is not computed.
2221
it('Should guard for Record 3', () => {
2322
const T = Type.Record(Type.String(), Type.Ref('A'))
2423
Assert.IsTrue(KindGuard.IsRecord(T))
2524
})
26-
// TRecord<TRecordKey, TComputed<..., [TRef<...>]> is computed due to interior computed.
2725
it('Should guard for Record 3', () => {
2826
const T = Type.Record(Type.String(), Type.Partial(Type.Ref('A')))
29-
Assert.IsTrue(KindGuard.IsComputed(T))
27+
Assert.IsTrue(KindGuard.IsRecord(T))
3028
})
31-
// TRecord<TRef<...>, TSchema> is computed as schematics may be transformed to TObject if finite
3229
it('Should guard for Record 4', () => {
3330
const T = Type.Record(Type.Ref('A'), Type.String())
34-
Assert.IsTrue(KindGuard.IsComputed(T))
31+
Assert.IsTrue(KindGuard.IsNever(T))
3532
})
3633
})

test/runtime/type/guard/kind/import.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ describe('guard/kind/TImport', () => {
151151
Assert.IsTrue(KindGuard.IsRef(T.$defs['R'].patternProperties['^(.*)$']))
152152
Assert.IsTrue(T.$defs['R'].patternProperties['^(.*)$'].$ref === 'T')
153153
})
154-
it('Should compute for Record 2', () => {
155-
const Module = Type.Module({
156-
T: Type.Number(),
157-
K: Type.Union([Type.Literal('x'), Type.Literal('y')]),
158-
R: Type.Record(Type.Ref('K'), Type.Ref('T')),
159-
})
160-
const T = Module.Import('R')
161-
Assert.IsTrue(KindGuard.IsObject(T.$defs['R']))
162-
Assert.IsTrue(KindGuard.IsNumber(T.$defs['R'].properties.x))
163-
Assert.IsTrue(KindGuard.IsNumber(T.$defs['R'].properties.x))
164-
})
154+
// it('Should compute for Record 2', () => {
155+
// const Module = Type.Module({
156+
// T: Type.Number(),
157+
// K: Type.Union([Type.Literal('x'), Type.Literal('y')]),
158+
// R: Type.Record(Type.Ref('K'), Type.Ref('T')),
159+
// })
160+
// const T = Module.Import('R')
161+
// Assert.IsTrue(KindGuard.IsObject(T.$defs['R']))
162+
// Assert.IsTrue(KindGuard.IsNumber(T.$defs['R'].properties.x))
163+
// Assert.IsTrue(KindGuard.IsNumber(T.$defs['R'].properties.x))
164+
// })
165165
// ----------------------------------------------------------------
166166
// Computed: Required
167167
// ----------------------------------------------------------------

test/runtime/type/guard/type/computed.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@ describe('guard/type/TComputed', () => {
1818
const T = Type.Record(Type.String(), Type.String())
1919
Assert.IsTrue(TypeGuard.IsRecord(T))
2020
})
21-
// TRecord<TRecordKey, TRef<...>> is not computed.
2221
it('Should guard for Record 3', () => {
2322
const T = Type.Record(Type.String(), Type.Ref('A'))
2423
Assert.IsTrue(TypeGuard.IsRecord(T))
2524
})
26-
// TRecord<TRecordKey, TComputed<..., [TRef<...>]> is computed due to interior computed.
2725
it('Should guard for Record 3', () => {
2826
const T = Type.Record(Type.String(), Type.Partial(Type.Ref('A')))
29-
Assert.IsTrue(TypeGuard.IsComputed(T))
27+
Assert.IsTrue(TypeGuard.IsRecord(T))
3028
})
31-
// TRecord<TRef<...>, TSchema> is computed as schematics may be transformed to TObject if finite
3229
it('Should guard for Record 4', () => {
3330
const T = Type.Record(Type.Ref('A'), Type.String())
34-
Assert.IsTrue(TypeGuard.IsComputed(T))
31+
Assert.IsTrue(TypeGuard.IsNever(T))
3532
})
3633
})

test/runtime/type/guard/type/import.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,17 @@ describe('guard/type/TImport', () => {
151151
Assert.IsTrue(TypeGuard.IsRef(T.$defs['R'].patternProperties['^(.*)$']))
152152
Assert.IsTrue(T.$defs['R'].patternProperties['^(.*)$'].$ref === 'T')
153153
})
154-
it('Should compute for Record 2', () => {
155-
const Module = Type.Module({
156-
T: Type.Number(),
157-
K: Type.Union([Type.Literal('x'), Type.Literal('y')]),
158-
R: Type.Record(Type.Ref('K'), Type.Ref('T')),
159-
})
160-
const T = Module.Import('R')
161-
Assert.IsTrue(TypeGuard.IsObject(T.$defs['R']))
162-
Assert.IsTrue(TypeGuard.IsNumber(T.$defs['R'].properties.x))
163-
Assert.IsTrue(TypeGuard.IsNumber(T.$defs['R'].properties.x))
164-
})
154+
// it('Should compute for Record 2', () => {
155+
// const Module = Type.Module({
156+
// T: Type.Number(),
157+
// K: Type.Union([Type.Literal('x'), Type.Literal('y')]),
158+
// R: Type.Record(Type.Ref('K'), Type.Ref('T')),
159+
// })
160+
// const T = Module.Import('R')
161+
// Assert.IsTrue(TypeGuard.IsObject(T.$defs['R']))
162+
// Assert.IsTrue(TypeGuard.IsNumber(T.$defs['R'].properties.x))
163+
// Assert.IsTrue(TypeGuard.IsNumber(T.$defs['R'].properties.x))
164+
// })
165165
// ----------------------------------------------------------------
166166
// Computed: Required
167167
// ----------------------------------------------------------------

test/static/import.ts

+30-30
Original file line numberDiff line numberDiff line change
@@ -58,49 +58,49 @@ import { Type, Static } from '@sinclair/typebox'
5858
// ------------------------------------------------------------------
5959
// prettier-ignore
6060
{
61-
const T = Type.Module({
62-
R: Type.Object({ x: Type.Number(), y: Type.Number() }),
63-
T: Type.Record(Type.String(), Type.Partial(Type.Ref('R'))),
64-
}).Import('T')
61+
// const T = Type.Module({
62+
// R: Type.Object({ x: Type.Number(), y: Type.Number() }),
63+
// T: Type.Record(Type.String(), Type.Partial(Type.Ref('R'))),
64+
// }).Import('T')
6565

66-
type T = Static<typeof T>
67-
Expect(T).ToStatic<{
68-
[key: string]: { x?: number, y?: number }
69-
}>()
66+
// type T = Static<typeof T>
67+
// Expect(T).ToStatic<{
68+
// [key: string]: { x?: number, y?: number }
69+
// }>()
7070
}
7171
// ------------------------------------------------------------------
7272
// Record 3
7373
// ------------------------------------------------------------------
7474
// prettier-ignore
7575
{
76-
const T = Type.Module({
77-
R: Type.Object({ x: Type.Number(), y: Type.Number() }),
78-
K: Type.Number(),
79-
T: Type.Record(Type.Ref('K'), Type.Partial(Type.Ref('R'))),
80-
}).Import('T')
76+
// const T = Type.Module({
77+
// R: Type.Object({ x: Type.Number(), y: Type.Number() }),
78+
// K: Type.Number(),
79+
// T: Type.Record(Type.Ref('K'), Type.Partial(Type.Ref('R'))),
80+
// }).Import('T')
8181

82-
type T = Static<typeof T>
83-
Expect(T).ToStatic<{
84-
[key: number]: { x?: number, y?: number }
85-
}>()
82+
// type T = Static<typeof T>
83+
// Expect(T).ToStatic<{
84+
// [key: number]: { x?: number, y?: number }
85+
// }>()
8686
}
8787
// ------------------------------------------------------------------
8888
// Record 4
8989
// ------------------------------------------------------------------
9090
// prettier-ignore
91-
{
92-
const T = Type.Module({
93-
R: Type.Object({ x: Type.Number(), y: Type.Number() }),
94-
K: Type.TemplateLiteral('${A|B|C}'),
95-
T: Type.Record(Type.Ref('K'), Type.Partial(Type.Ref('R'))),
96-
}).Import('T')
97-
type T = Static<typeof T>
98-
Expect(T).ToStatic<{
99-
A: { x?: number, y?: number },
100-
B: { x?: number, y?: number },
101-
C: { x?: number, y?: number }
102-
}>()
103-
}
91+
// {
92+
// const T = Type.Module({
93+
// R: Type.Object({ x: Type.Number(), y: Type.Number() }),
94+
// K: Type.TemplateLiteral('${A|B|C}'),
95+
// T: Type.Record(Type.Ref('K'), Type.Partial(Type.Ref('R'))),
96+
// }).Import('T')
97+
// type T = Static<typeof T>
98+
// Expect(T).ToStatic<{
99+
// A: { x?: number, y?: number },
100+
// B: { x?: number, y?: number },
101+
// C: { x?: number, y?: number }
102+
// }>()
103+
// }
104104
// ------------------------------------------------------------------
105105
// Modifiers 1
106106
// ------------------------------------------------------------------

0 commit comments

Comments
 (0)