Revision 0.32.16 (#791)

* Update Indexed Union Evaluation

* Use Reduce Strategy for Union and Intersect Value Conversion

* Add Path to Transform Codec Errors

* Support Control Character Escape in Template Literal Syntax

* Intersect Union Convert Test Case

* Revision 0.32.16
This commit is contained in:
sinclairzx81
2024-03-20 02:25:53 +09:00
committed by GitHub
parent abe71c68cd
commit 9fa2e2801c
18 changed files with 334 additions and 151 deletions
+28 -1
View File
@@ -1,5 +1,5 @@
import { Expect } from './assert'
import { Type, TOptional, TObject, TIntersect, TNumber, TBoolean } from '@sinclair/typebox'
import { Type, TOptional, TObject, TUnion, TIntersect, TNumber, TString, TBoolean } from '@sinclair/typebox'
// ----------------------------------------------------------------------------
// Overlapping - Non Varying
@@ -184,3 +184,30 @@ import { Type, TOptional, TObject, TIntersect, TNumber, TBoolean } from '@sincla
])
])
}
// ------------------------------------------------------------------
// Union
// ------------------------------------------------------------------
// prettier-ignore
{
const T: TObject<{
x: TNumber;
}> = Type.Composite([
Type.Union([
Type.Object({ x: Type.Number() }),
Type.Object({ y: Type.Number() })
]),
Type.Object({ x: Type.Number() })
])
}
// prettier-ignore
{
const T: TObject<{
x: TIntersect<[TUnion<[TString, TString]>, TNumber]>;
}> = Type.Composite([
Type.Union([
Type.Object({ x: Type.String() }),
Type.Object({ x: Type.String() })
]),
Type.Object({ x: Type.Number() })
])
}
+14
View File
@@ -175,3 +175,17 @@ import { Type, Static } from '@sinclair/typebox'
const T = Type.Record(Type.Enum(E), Type.Number())
Expect(T).ToStatic<{ [x: string]: number }>
}
// ------------------------------------------------------------------
// Dollar Sign Escape
// https://github.com/sinclairzx81/typebox/issues/794
// ------------------------------------------------------------------
// prettier-ignore
{
const K = Type.TemplateLiteral('$prop${A|B|C}') // issue
const T = Type.Record(K, Type.String())
Expect(T).ToStatic<{
'$propA': string,
'$propB': string,
'$propC': string
}>()
}
+35
View File
@@ -77,3 +77,38 @@ import { Type } from '@sinclair/typebox'
const T = Type.TemplateLiteral([Type.Literal('hello'), A])
Expect(T).ToStatic<'helloA' | 'helloB'>()
}
// ------------------------------------------------------------------
// Dollar Sign Escape
// https://github.com/sinclairzx81/typebox/issues/794
// ------------------------------------------------------------------
// prettier-ignore
{
const T = Type.TemplateLiteral('$prop${A|B|C}') // issue
Expect(T).ToStatic<'$propA' | '$propB' | '$propC'>()
}
// prettier-ignore
{
const T = Type.TemplateLiteral('$prop${A|B|C}x') // trailing
Expect(T).ToStatic<'$propAx' | '$propBx' | '$propCx'>()
}
// prettier-ignore
{
const T = Type.TemplateLiteral('$prop${A|B|C}x}') // non-greedy
Expect(T).ToStatic<'$propAx}' | '$propBx}' | '$propCx}'>()
}
// prettier-ignore
{
const T = Type.TemplateLiteral('$prop${A|B|C}x}${X|Y}') // distributive - non-greedy
Expect(T).ToStatic<
'$propAx}X' | '$propBx}X' | '$propCx}X' |
'$propAx}Y' | '$propBx}Y' | '$propCx}Y'
>()
}
// prettier-ignore
{
const T = Type.TemplateLiteral('$prop${A|B|C}x}${X|Y}x') // distributive - non-greedy - trailing
Expect(T).ToStatic<
'$propAx}Xx' | '$propBx}Xx' | '$propCx}Xx' |
'$propAx}Yx' | '$propBx}Yx' | '$propCx}Yx'
>()
}