-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1504082
commit c8d8a70
Showing
15 changed files
with
494 additions
and
1,383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
## [0.29.2](https://www.npmjs.com/package/@sinclair/typebox/v/0.29.2) | ||
|
||
## Overview | ||
|
||
Revision 0.29.2 includes enhancements to `Type.Index` | ||
|
||
This revision contains no breaking changes | ||
|
||
## Contents | ||
|
||
- Enhancements | ||
- [Modifier Index Resolver](#Modifier-Index-Resolver) | ||
- [Indexed Intersect](#Indexed-Intersect) | ||
- [Indexed Union](#Indexed-Union) | ||
- [Composite](#Composite) | ||
|
||
<a name="Modifier-Index-Resolver"></a> | ||
|
||
## Modifier Index Resolver | ||
|
||
Revision 0.29.2 re-introduces optional property narrowing for Indexed Access Types. This functionality is specific when indexing overlapping properties with one or more optional modifiers. Revision 0.28.0 attempted to implement this narrowing, however was pulled due to instantiation issues raised on issue [419](https://github.com/sinclairzx81/typebox/issues/419) (specific to composite narrowing) | ||
|
||
Revision 0.29.2 attempts to re-introduce this functionality using a different resolution strategy. It uses Indexed Access Types as the construct in which to apply such narrowing and expands upon Union and Intersection type normalization for optional modifier unwrap and remapping. This approach unifies Composite inference with Index Access Types and makes provisions for a possible `Type.Mapped` feature in later releases. | ||
|
||
<a name="Indexed-Intersect"></a> | ||
|
||
## Indexed Intersect | ||
|
||
The following are the index resolver cases for intersect types. | ||
|
||
### Case 1 | ||
```typescript | ||
const T = Type.Intersect([ | ||
Type.Object({ x: Type.Optional(Type.Number()) }), | ||
Type.Object({ x: Type.Optional(Type.Number()) }) | ||
]) | ||
|
||
const I = Type.Index(T, ['x']) | ||
|
||
// type I = TOptional<TUnion<[TNumber, TNumber]>> | ||
``` | ||
### Case 2 | ||
```typescript | ||
const T = Type.Intersect([ | ||
Type.Object({ x: Type.Optional(Type.Number()) }), | ||
Type.Object({ x: Type.Number() }) | ||
]) | ||
|
||
const I = Type.Index(T, ['x']) | ||
|
||
// type I = TUnion<[TNumber, TNumber]> | ||
``` | ||
### Case 3 | ||
```typescript | ||
const T = Type.Intersect([ | ||
Type.Object({ x: Type.Number() }), | ||
Type.Object({ x: Type.Number() }) | ||
]) | ||
|
||
const I = Type.Index(T, ['x']) | ||
|
||
// type I = TUnion<[TNumber, TNumber]> | ||
``` | ||
<a name="Indexed-Union"></a> | ||
|
||
## Indexed Union | ||
|
||
The following are the index resolver cases for union types. | ||
|
||
### Case 1 | ||
```typescript | ||
const T = Type.Union([ | ||
Type.Object({ x: Type.Optional(Type.Number()) }), | ||
Type.Object({ x: Type.Optional(Type.Number()) }) | ||
]) | ||
|
||
const I = Type.Index(T, ['x']) | ||
|
||
// type I = TOptional<TUnion<[TNumber, TNumber]>> | ||
``` | ||
### Case 2 | ||
```typescript | ||
const T = Type.Union([ | ||
Type.Object({ x: Type.Optional(Type.Number()) }), | ||
Type.Object({ x: Type.Number() }) | ||
]) | ||
|
||
const I = Type.Index(T, ['x']) | ||
|
||
// type I = TOptional<TUnion<[TNumber, TNumber]>> | ||
``` | ||
### Case 3 | ||
```typescript | ||
const T = Type.Union([ | ||
Type.Object({ x: Type.Number() }), | ||
Type.Object({ x: Type.Number() }) | ||
]) | ||
|
||
const I = Type.Index(T, ['x']) | ||
|
||
// type I = TUnion<[TNumber, TNumber]> | ||
``` | ||
<a name="Composite"></a> | ||
|
||
## Composite | ||
|
||
The following are the resolver cases for indexed types when applied to composite intersection. | ||
|
||
### Case 1 | ||
```typescript | ||
const T = Type.Composite([ | ||
Type.Object({ x: Type.Optional(Type.Number()) }), | ||
Type.Object({ x: Type.Optional(Type.Number()) }) | ||
]) | ||
|
||
// type T = TObject<{ | ||
// x: TOptional<TUnion<[TNumber, TNumber]>> | ||
// }> | ||
``` | ||
### Case 2 | ||
```typescript | ||
const T = Type.Composite([ | ||
Type.Object({ x: Type.Optional(Type.Number()) }), | ||
Type.Object({ x: Type.Number() }) | ||
]) | ||
|
||
// type T = TObject<{ | ||
// x: TUnion<[TNumber, TNumber]> | ||
// }> | ||
``` | ||
### Case 3 | ||
```typescript | ||
const T = Type.Composite([ | ||
Type.Object({ x: Type.Number() }), | ||
Type.Object({ x: Type.Number() }) | ||
]) | ||
|
||
// type T = TObject<{ | ||
// x: TUnion<[TNumber, TNumber]> | ||
// }> | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.