mirror of
https://github.com/zoriya/typebox.git
synced 2025-12-06 06:46:10 +00:00
Revision 0.32.34 (#914)
* Fix Embedded TemplateLiteral Generation * TypeScript 5.5.2 * Version
This commit is contained in:
@@ -32,7 +32,7 @@ export async function benchmark() {
|
||||
// Test
|
||||
// -------------------------------------------------------------------------------
|
||||
export async function test_typescript() {
|
||||
for (const version of ['4.9.5', '5.0.4', '5.1.3', '5.1.6', '5.2.2', '5.3.2', '5.3.3', '5.4.3', 'next', 'latest']) {
|
||||
for (const version of ['4.9.5', '5.0.4', '5.1.3', '5.1.6', '5.2.2', '5.3.2', '5.3.3', '5.4.3', '5.4.5', 'next', 'latest']) {
|
||||
await shell(`npm install typescript@${version} --no-save`)
|
||||
await test_static()
|
||||
}
|
||||
|
||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@sinclair/typebox",
|
||||
"version": "0.32.33",
|
||||
"version": "0.32.34",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@sinclair/typebox",
|
||||
"version": "0.32.33",
|
||||
"version": "0.32.34",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@arethetypeswrong/cli": "^0.13.2",
|
||||
@@ -17,7 +17,7 @@
|
||||
"ajv-formats": "^2.1.1",
|
||||
"mocha": "^10.4.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.4.5"
|
||||
"typescript": "^5.5.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@andrewbranch/untar.js": {
|
||||
@@ -1576,9 +1576,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.4.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz",
|
||||
"integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==",
|
||||
"version": "5.5.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz",
|
||||
"integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
@@ -2738,9 +2738,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"typescript": {
|
||||
"version": "5.4.5",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz",
|
||||
"integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==",
|
||||
"version": "5.5.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz",
|
||||
"integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==",
|
||||
"dev": true
|
||||
},
|
||||
"undici-types": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sinclair/typebox",
|
||||
"version": "0.32.33",
|
||||
"version": "0.32.34",
|
||||
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
|
||||
"keywords": [
|
||||
"typescript",
|
||||
@@ -37,6 +37,6 @@
|
||||
"ajv-formats": "^2.1.1",
|
||||
"mocha": "^10.4.0",
|
||||
"prettier": "^2.7.1",
|
||||
"typescript": "^5.4.5"
|
||||
"typescript": "^5.5.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,7 @@ type TFromTemplateLiteralUnionKinds<T extends TTemplateLiteralKind[]> =
|
||||
type TFromTemplateLiteralKinds<T extends TTemplateLiteralKind[], Acc extends TLiteralValue[][] = []> =
|
||||
T extends [infer L extends TTemplateLiteralKind, ...infer R extends TTemplateLiteralKind[]]
|
||||
? (
|
||||
L extends TTemplateLiteral<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<[...S, ...R], Acc> :
|
||||
L extends TLiteral<infer S extends TLiteralValue> ? TFromTemplateLiteralKinds<R, [...Acc, [S]]> :
|
||||
L extends TUnion<infer S extends TTemplateLiteralKind[]> ? TFromTemplateLiteralKinds<R, [...Acc, TFromTemplateLiteralUnionKinds<S>]> :
|
||||
L extends TBoolean ? TFromTemplateLiteralKinds<R, [...Acc, ['true', 'false']]> :
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { TypeGuard } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
import { Type, TemplateLiteralGenerate } from '@sinclair/typebox'
|
||||
import { Assert } from '../../../assert/index'
|
||||
|
||||
describe('guard/type/TTemplateLiteral', () => {
|
||||
@@ -44,4 +44,39 @@ describe('guard/type/TTemplateLiteral', () => {
|
||||
T.pattern = T.pattern.slice(0, T.pattern.length - 1)
|
||||
Assert.IsFalse(TypeGuard.IsTemplateLiteral(T))
|
||||
})
|
||||
// ----------------------------------------------------------------
|
||||
// issue: https://github.com/sinclairzx81/typebox/issues/913
|
||||
// ----------------------------------------------------------------
|
||||
it('Should generate embedded template literal 1', () => {
|
||||
const A = Type.TemplateLiteral([Type.Union([Type.Literal('A'), Type.Literal('B')])])
|
||||
const B = Type.TemplateLiteral([Type.Union([Type.Literal('X'), Type.Literal('Y')])])
|
||||
const L = Type.TemplateLiteral([Type.Literal('KEY'), A, B])
|
||||
const T = TemplateLiteralGenerate(L)
|
||||
Assert.IsEqual(T, ['KEYAX', 'KEYAY', 'KEYBX', 'KEYBY'])
|
||||
})
|
||||
it('Should generate embedded template literal 2', () => {
|
||||
const A = Type.TemplateLiteral([Type.Union([Type.Literal('A'), Type.Literal('B')])])
|
||||
const B = Type.TemplateLiteral([Type.Union([Type.Literal('X'), Type.Literal('Y')])])
|
||||
const L = Type.TemplateLiteral([A, Type.Literal('KEY'), B])
|
||||
const T = TemplateLiteralGenerate(L)
|
||||
Assert.IsEqual(T, ['AKEYX', 'AKEYY', 'BKEYX', 'BKEYY'])
|
||||
})
|
||||
it('Should generate embedded template literal 3', () => {
|
||||
const A = Type.TemplateLiteral([Type.Union([Type.Literal('A'), Type.Literal('B')])])
|
||||
const B = Type.TemplateLiteral([Type.Union([Type.Literal('X'), Type.Literal('Y')])])
|
||||
const L = Type.TemplateLiteral([A, B, Type.Literal('KEY')])
|
||||
const T = TemplateLiteralGenerate(L)
|
||||
Assert.IsEqual(T, ['AXKEY', 'AYKEY', 'BXKEY', 'BYKEY'])
|
||||
})
|
||||
it('Should map embedded template literal', () => {
|
||||
const A = Type.TemplateLiteral([Type.Union([Type.Literal('A'), Type.Literal('B')])])
|
||||
const B = Type.TemplateLiteral([Type.Union([Type.Literal('X'), Type.Literal('Y')])])
|
||||
const L = Type.TemplateLiteral([Type.Literal('KEY'), A, B])
|
||||
const T = Type.Mapped(L, (K) => Type.Null())
|
||||
Assert.IsTrue(TypeGuard.IsObject(T))
|
||||
Assert.IsTrue(TypeGuard.IsNull(T.properties.KEYAX))
|
||||
Assert.IsTrue(TypeGuard.IsNull(T.properties.KEYAY))
|
||||
Assert.IsTrue(TypeGuard.IsNull(T.properties.KEYBX))
|
||||
Assert.IsTrue(TypeGuard.IsNull(T.properties.KEYBY))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -112,3 +112,18 @@ import { Type } from '@sinclair/typebox'
|
||||
'$propAx}Yx' | '$propBx}Yx' | '$propCx}Yx'
|
||||
>()
|
||||
}
|
||||
// ---------------------------------------------------------------------
|
||||
// issue: https://github.com/sinclairzx81/typebox/issues/913
|
||||
// ---------------------------------------------------------------------
|
||||
{
|
||||
const A = Type.TemplateLiteral([Type.Union([Type.Literal('A'), Type.Literal('B')])])
|
||||
const B = Type.TemplateLiteral([Type.Union([Type.Literal('X'), Type.Literal('Y')])])
|
||||
const L = Type.TemplateLiteral([Type.Literal('KEY'), A, B])
|
||||
const T = Type.Mapped(L, (K) => Type.Null())
|
||||
Expect(T).ToStatic<{
|
||||
KEYAX: null
|
||||
KEYAY: null
|
||||
KEYBX: null
|
||||
KEYBY: null
|
||||
}>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user