You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Conditional types are supported with `Type.Extends`, `Type.Exclude` and `Type.Extract`
779
+
TypeBox supports conditional types with `Type.Extends`. This type will perform a structural assignment check for the first two parameters and return a `true` or `false` type from the second two parameters. The types `Type.Exclude` and `Type.Extract` are also supported.
780
780
781
781
```typescript
782
782
// TypeScript
783
783
784
784
typeT0=stringextendsnumber?true:false// type T0 = false
785
785
786
-
typeT1=Extract<string|number, number>// type T1 = number
786
+
typeT1=Extract<(1|2|3), 1>// type T1 = 1
787
787
788
-
typeT2=Exclude<string|number, number>// type T2 = string
TypeBox supports Template Literal types using`Type.TemplateLiteral`. These types can be created using a simple template DSL syntax, however more complex template literals can be created by passing an array of literal and union types. The examples below show the template DSL syntax.
822
+
TypeBox supports template literal types with`Type.TemplateLiteral`. This type implements an embedded DSL syntax to match the TypeScript template literal syntax. This type can also be composed by passing an array of union and literal types as parameters. The following example shows the DSL syntax.
811
823
812
824
```typescript
813
825
// TypeScript
@@ -853,7 +865,7 @@ const R = Type.Record(T, Type.String()) // const R = {
853
865
854
866
### Indexed Access Types
855
867
856
-
TypeBox supports Indexed Access types using `Type.Index`. This feature provides a consistent way to access property types without having to extract them from the underlying schema representation. Indexed accessors are supported for object and tuples, as well as nested union and intersect types.
868
+
TypeBox supports indexed access types using `Type.Index`. This type provides a consistent way to access interior property and array element types without having to extract them from the underlying schema representation. Indexed access types are supported for object, array, tuple, union and intersect types.
857
869
858
870
```typescript
859
871
constT=Type.Object({ // const T = {
@@ -888,7 +900,7 @@ const C = Type.Index(T, Type.KeyOf(T)) // const C = {
888
900
889
901
### Not Types
890
902
891
-
TypeBox has partial support for the JSON schema `not` keyword with `Type.Not`. This type is synonymous with the concept of a [negated types](https://github.com/microsoft/TypeScript/issues/4196) which are not supported in the TypeScript language. TypeBox does provide partial inference support via the intersection of `T¬U` (where all negated types infer as `unknown`). This can be used in the following context.
903
+
TypeBox provides support for the `not` keyword with `Type.Not`. This type is synonymous with [negated types](https://github.com/microsoft/TypeScript/issues/4196) which are not supported in the TypeScript language. Partial inference of this type can be attained via the intersection of `T¬U` (where all Not types infer as `unknown`). This approach can be used to narrow for broader types in the following context.
0 commit comments