Skip to content

Commit 6a1bb76

Browse files
authored
Version 1.0.33 (#1394)
* Re-Enable Dual Publishing * Pick Update | Migration Guide * Import Manifest * ChangeLog * Version
1 parent 3211a32 commit 6a1bb76

13 files changed

Lines changed: 297 additions & 190 deletions

File tree

changelog/1.0.0-migration.md

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ This document covers upgrading from TypeBox 0.34.x to 1.0. While most of the API
66

77
## Contents
88

9-
- [ESM Package](#ESM)
109
- [Kind, Hint, ReadonlyKind and OptionalKind](#Symbols)
1110
- [Type.Date and Type.Uint8Array](#Globals)
1211
- [Type.Recursive](#Recursive)
1312
- [Type.RegExp](#RegExp)
1413
- [Type.Composite](#Composite)
1514
- [Type.Transform](#Transform)
1615
- [Type.Const](#Const)
16+
- [Type.Pick and Type.Omit](#PickOmit)
1717
- [TypeCompiler](#TypeCompiler)
1818
- [References](#References)
1919
- [FormatRegistry](#FormatRegistry)
@@ -24,12 +24,6 @@ This document covers upgrading from TypeBox 0.34.x to 1.0. While most of the API
2424
- [SetErrorFunction](#SetErrorFunction)
2525
- [CustomErrors](#CustomErrors)
2626

27-
<a name="ESM"></a>
28-
29-
## ESM Package
30-
31-
Version 1.0 is published as an ESM-only package. Users will need to ensure their environments support ESM module resolution.
32-
3327
<a name="Symbols"></a>
3428

3529
## Kind, Hint, ReadonlyKind and OptionalKind
@@ -273,6 +267,46 @@ const S = Type.Script({ T }, `{
273267
// }>
274268
```
275269

270+
<a name="PickOmit"></a>
271+
272+
## Type.Pick and Type.Omit
273+
274+
Version 1.0 updates Pick and Omit to return evaluated Object types when applied to Union and Intersect types. This change aligns with V1’s ability to evaluate logical type expressions for mapped types. As a consequence, the return structures of Pick and Omit may vary depending on the source type being used.
275+
276+
In 0.34.x, Pick and Omit would simply traverse a logical type expression and select properties from embedded Object types. In 1.0, Pick and Omit evaluate the result into a normalized Object type. Both 0.34.x and 1.0 return semantically equivalent types, but in 1.0 the result is reduced to its simplest form.
277+
278+
### Fallback
279+
280+
[Pick](/example/legacy/pick.ts) | [Omit](/example/legacy/omit.ts)
281+
282+
### Example
283+
284+
0.34.x
285+
286+
```typescript
287+
const X = Type.Object({ x: Type.Number(), z: Type.Number() })
288+
const Y = Type.Object({ y: Type.Number(), z: Type.Literal(1) })
289+
const Z = Type.Intersect([X, Y])
290+
291+
const T = Type.Pick(Z, ['z']) // const T: TIntersect<[TObject<{
292+
// z: TNumber;
293+
// }>, TObject<{
294+
// z: TLiteral<1>
295+
// }>]>
296+
```
297+
298+
1.0.0
299+
300+
```typescript
301+
const X = Type.Object({ x: Type.Number(), z: Type.Number() })
302+
const Y = Type.Object({ y: Type.Number(), z: Type.Literal(1) })
303+
const Z = Type.Intersect([X, Y])
304+
305+
const T = Type.Pick(Z, ['z']) // const T: Type.TObject<{
306+
// z: Type.TLiteral<1>;
307+
// }>
308+
```
309+
276310

277311
<a name="TypeCompiler"></a>
278312

changelog/1.0.0.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
---
44

55
### Version Updates
6+
- [Revision 1.0.33](https://github.com/sinclairzx81/typebox/pull/1394)
7+
- Re-Enable Dual Publishing for ESM and CommonJS
68
- [Revision 1.0.32](https://github.com/sinclairzx81/typebox/pull/1393)
79
- Fix Object Collapse Evaluator for Overlapping Properties (Pick, Omit and Index)
810
- [Revision 1.0.31](https://github.com/sinclairzx81/typebox/pull/1390)

deno.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// --------------------------------------------------------------
2121
// Build
2222
// --------------------------------------------------------------
23-
"tasksmith": "https://raw.githubusercontent.com/sinclairzx81/tasksmith/0.9.2/src/index.ts",
23+
"tasksmith": "https://raw.githubusercontent.com/sinclairzx81/tasksmith/0.9.5/src/index.ts",
2424
"parsebox": "https://raw.githubusercontent.com/sinclairzx81/parsebox/0.11.0/src/index.ts",
2525
// --------------------------------------------------------------
2626
// Test

deno.lock

Lines changed: 87 additions & 152 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

design/syntax/syntax.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ const Extends = Runtime.Union([
269269
const Base = Runtime.Union([
270270
Runtime.Tuple([Runtime.Const(LParen), Runtime.Ref('Type'), Runtime.Const(RParen)]),
271271
Runtime.Ref('Keyword'),
272-
Runtime.Ref('Object'),
272+
Runtime.Ref('_Object_'),
273273
Runtime.Ref('Tuple'),
274274
Runtime.Ref('TemplateLiteral'),
275275
Runtime.Ref('Literal'),
@@ -426,7 +426,7 @@ const Properties = Runtime.Tuple([
426426
// ------------------------------------------------------------------
427427
// Object
428428
// ------------------------------------------------------------------
429-
const Object = Runtime.Ref('Properties')
429+
const _Object_ = Runtime.Ref('Properties')
430430
// ------------------------------------------------------------------
431431
// ElementNamed
432432
// ------------------------------------------------------------------
@@ -954,7 +954,7 @@ export const SyntaxModule = new Runtime.Module({
954954
PropertyDelimiter,
955955
PropertyList,
956956
Properties,
957-
Object,
957+
_Object_,
958958

959959
ElementNamed,
960960
ElementReadonlyOptional,

src/type/engine/object/from-intersect.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,36 @@ import { Guard } from '../../../guard/index.ts'
3333
import { type TSchema } from '../../types/schema.ts'
3434
import { type TProperties } from '../../types/properties.ts'
3535
import { type TFromType, FromType } from './from-type.ts'
36+
import { type TEvaluateIntersect, EvaluateIntersect } from '../evaluate/evaluate.ts'
3637

3738
// ------------------------------------------------------------------
3839
// CollapseProperties
3940
// ------------------------------------------------------------------
4041
type TCollapseIntersectProperties<Left extends TProperties, Right extends TProperties,
4142
LeftKeys extends keyof Left = Exclude<keyof Left, keyof Right>,
4243
RightKeys extends keyof Right = Exclude<keyof Right, keyof Left>,
44+
SharedKeys extends keyof Left & keyof Right = Extract<keyof Left, keyof Right>,
45+
4346
LeftProperties extends TProperties = { [Key in LeftKeys]: Left[Key] },
4447
RightProperties extends TProperties = { [Key in RightKeys]: Right[Key] },
45-
Result extends TProperties = Memory.TAssign<LeftProperties, RightProperties>
46-
> = Result
48+
SharedProperties extends TProperties = { [Key in SharedKeys]: TEvaluateIntersect<[Left[Key], Right[Key]]> },
49+
50+
Unique extends TProperties = Memory.TAssign<LeftProperties, RightProperties>,
51+
Shared extends TProperties = Memory.TAssign<Unique, SharedProperties>
52+
> = Shared
4753

4854
function CollapseIntersectProperties<Left extends TProperties, Right extends TProperties>(left: Left, right: Right): TCollapseIntersectProperties<Left, Right> {
4955
const leftKeys = Guard.Keys(left).filter((key) => !Guard.HasPropertyKey(right, key))
5056
const rightKeys = Guard.Keys(right).filter((key) => !Guard.HasPropertyKey(left, key))
51-
const leftProperties = leftKeys.reduce((result, key) => Memory.Assign(result, { [key]: left[key] }), {})
52-
const rightProperties = rightKeys.reduce((result, key) => Memory.Assign(result, { [key]: right[key] }), {})
53-
const result = Memory.Assign(leftProperties, rightProperties)
54-
return result as never
57+
const sharedKeys = Guard.Keys(left).filter((key) => Guard.HasPropertyKey(right, key))
58+
59+
const leftProperties = leftKeys.reduce((result, key) => ({ ...result, [key]: left[key] }), {})
60+
const rightProperties = rightKeys.reduce((result, key) => ({ ...result, [key]: right[key] }), {})
61+
const sharedProperties = sharedKeys.reduce((result, key) => ({ ...result, [key]: EvaluateIntersect([left[key], right[key]]) }), {})
62+
63+
const unique = Memory.Assign(leftProperties, rightProperties)
64+
const shared = Memory.Assign(unique, sharedProperties)
65+
return shared as never
5566
}
5667
// ------------------------------------------------------------------
5768
// Intersect

src/type/script/mapping.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ export function ExtendsMapping(input: [unknown, unknown, unknown, unknown, unkno
519519
: []
520520
}
521521
// -------------------------------------------------------------------
522-
// Base: ['(', Type, ')'] | Keyword | Object | Tuple | TemplateLiteral | Literal | Constructor | Function | Mapped | Options | GenericCall | Reference
522+
// Base: ['(', Type, ')'] | Keyword | _Object_ | Tuple | TemplateLiteral | Literal | Constructor | Function | Mapped | Options | GenericCall | Reference
523523
// -------------------------------------------------------------------
524524
export type TBaseMapping<Input extends [unknown, unknown, unknown] | unknown> = (
525525
Input extends ['(', infer Type extends T.TSchema, ')'] ? Type :
@@ -881,14 +881,14 @@ export function PropertiesMapping(input: [unknown, unknown, unknown]): unknown {
881881
return PropertiesReduce(input[1] as T.TProperties[])
882882
}
883883
// -------------------------------------------------------------------
884-
// Object: Properties
884+
// _Object_: Properties
885885
// -------------------------------------------------------------------
886-
export type TObjectMapping<Input extends unknown> = (
886+
export type T_Object_Mapping<Input extends unknown> = (
887887
Input extends [infer Properties extends T.TProperties, infer _PatternProperties extends T.TProperties]
888888
? T.TObject<Properties>
889889
: never
890890
)
891-
export function ObjectMapping(input: unknown): unknown {
891+
export function _Object_Mapping(input: unknown): unknown {
892892
const [properties, patternProperties] = input as [T.TProperties, T.TProperties]
893893
const options = Guard.IsEqual(Guard.Keys(patternProperties).length, 0) ? {} : { patternProperties }
894894
return T.Object(properties, options)

0 commit comments

Comments
 (0)