Skip to content

Commit 706a2bb

Browse files
authored
Version 1.0.35 (#1396)
* Support Optional SemiColon | KeyOf Any Semantics * ChangeLog * Version
1 parent f64a729 commit 706a2bb

10 files changed

Lines changed: 130 additions & 22 deletions

File tree

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.35](https://github.com/sinclairzx81/typebox/pull/1396)
7+
- Support Optional SemiColon | KeyOf Any Semantics
68
- [Revision 1.0.34](https://github.com/sinclairzx81/typebox/pull/1395)
79
- Revert Dual Publishing due to TypeScript Playground Automatic Type Acquisition (ATA) Issue
810
- [Revision 1.0.33](https://github.com/sinclairzx81/typebox/pull/1394)

design/syntax/syntax.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@ const GenericCall = Runtime.Tuple([
145145
Runtime.Ref('GenericCallArguments'),
146146
])
147147
// ------------------------------------------------------------------
148+
// OptionalSemiColon
149+
// ------------------------------------------------------------------
150+
const OptionalSemiColon = Runtime.Union([
151+
Runtime.Tuple([Runtime.Const(SemiColon)]),
152+
Runtime.Tuple([])
153+
])
154+
// ------------------------------------------------------------------
148155
// Reference
149156
// ------------------------------------------------------------------
150157
const Reference = Runtime.Ident()
@@ -610,7 +617,8 @@ const Mapped = Runtime.Tuple([
610617
Runtime.Ref('MappedOptional'),
611618
Runtime.Const(Colon),
612619
Runtime.Ref('Type'),
613-
Runtime.Const(RBrace)
620+
Runtime.Ref('OptionalSemiColon'),
621+
Runtime.Const(RBrace),
614622
])
615623
// ------------------------------------------------------------------
616624
// Options
@@ -865,7 +873,8 @@ const ModuleDeclaration = Runtime.Tuple([
865873
Runtime.Ref('InterfaceDeclaration'),
866874
Runtime.Ref('TypeAliasDeclarationGeneric'),
867875
Runtime.Ref('TypeAliasDeclaration'),
868-
])
876+
]),
877+
Runtime.Ref('OptionalSemiColon')
869878
])
870879
// ------------------------------------------------------------------
871880
// Module
@@ -901,6 +910,8 @@ export const SyntaxModule = new Runtime.Module({
901910
GenericCallArguments,
902911
GenericCall,
903912

913+
OptionalSemiColon,
914+
904915
KeywordString,
905916
KeywordNumber,
906917
KeywordBoolean,

src/type/engine/keyof/from-any.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*--------------------------------------------------------------------------
2+
3+
TypeBox
4+
5+
The MIT License (MIT)
6+
7+
Copyright (c) 2017-2025 Haydn Paterson
8+
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in
17+
all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
THE SOFTWARE.
26+
27+
---------------------------------------------------------------------------*/
28+
29+
// deno-fmt-ignore-file
30+
31+
import { type TNumber, Number } from '../../types/number.ts'
32+
import { type TString, String } from '../../types/string.ts'
33+
import { type TSymbol, Symbol } from '../../types/symbol.ts'
34+
import { type TUnion, Union } from '../../types/union.ts'
35+
36+
export type TFromAny<Result = TUnion<[TNumber, TString, TSymbol]>> = Result
37+
export function FromAny(): TFromAny {
38+
return Union([Number(), String(), Symbol()])
39+
}

src/type/engine/keyof/from-array.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ THE SOFTWARE.
2929
// deno-fmt-ignore-file
3030

3131
import { type TSchema } from '../../types/index.ts'
32-
import { type TNumber, Number } from "../../types/number.ts"
32+
import { type TNumber, Number } from '../../types/number.ts'
3333

3434
export type TFromArray<_Type extends TSchema> = TNumber
3535
export function FromArray<_Type extends TSchema>(_type: _Type): TFromArray<_Type> {

src/type/engine/keyof/instantiate.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ THE SOFTWARE.
3131
import { Memory } from '../../../system/memory/index.ts'
3232
import { type TSchema, type TSchemaOptions } from '../../types/schema.ts'
3333
import { type TProperties } from '../../types/properties.ts'
34+
import { type TAny, IsAny } from '../../types/any.ts'
3435
import { type TArray, IsArray } from '../../types/array.ts'
3536
import { type TCyclic, IsCyclic } from '../../types/cyclic.ts'
3637
import { type TIntersect, IsIntersect } from '../../types/intersect.ts'
@@ -47,7 +48,8 @@ import { type TCollapseToObject, CollapseToObject } from '../object/index.ts'
4748
// ------------------------------------------------------------------
4849
// Computed
4950
// ------------------------------------------------------------------
50-
import { type TFromArray, FromArray } from "./from-array.ts"
51+
import { type TFromAny, FromAny } from './from-any.ts'
52+
import { type TFromArray, FromArray } from './from-array.ts'
5153
import { type TFromObject, FromObject } from './from-object.ts'
5254
import { type TFromRecord, FromRecord } from './from-record.ts'
5355
import { type TFromTuple, FromTuple } from './from-tuple.ts'
@@ -80,17 +82,19 @@ function NormalizeType<Type extends TSchema>(type: Type): TNormalizeType<Type> {
8082
// Action
8183
// ------------------------------------------------------------------
8284
export type TKeyOfAction<Type extends TSchema,
83-
Normalized extends TSchema = TNormalizeType<Type>
85+
Normal extends TSchema = TNormalizeType<Type>
8486
> = (
85-
Normalized extends TArray<infer Type extends TSchema> ? TFromArray<Type> :
86-
Normalized extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> :
87-
Normalized extends TRecord ? TFromRecord<Normalized> :
88-
Normalized extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> :
87+
Normal extends TAny ? TFromAny :
88+
Normal extends TArray<infer Type extends TSchema> ? TFromArray<Type> :
89+
Normal extends TObject<infer Properties extends TProperties> ? TFromObject<Properties> :
90+
Normal extends TRecord ? TFromRecord<Normal> :
91+
Normal extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types> :
8992
TNever
9093
)
9194
export function KeyOfAction<Type extends TSchema>(type: Type): TKeyOfAction<Type> {
9295
const normal = NormalizeType(type)
9396
return (
97+
IsAny(normal) ? FromAny() :
9498
IsArray(normal) ? FromArray(normal.items) :
9599
IsObject(normal) ? FromObject(normal.properties) :
96100
IsRecord(normal) ? FromRecord(normal) :

src/type/script/mapping.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,14 @@ export function GenericCallMapping(input: [unknown, unknown]): unknown {
246246
return IntrinsicOrCall(input[0] as string, input[1] as T.TSchema[])
247247
}
248248
// -------------------------------------------------------------------
249+
// OptionalSemiColon: [';'] | []
250+
// -------------------------------------------------------------------
251+
export type TOptionalSemiColonMapping<Input extends [unknown] | []>
252+
= null
253+
export function OptionalSemiColonMapping(input: [unknown] | []): unknown {
254+
return null
255+
}
256+
// -------------------------------------------------------------------
249257
// KeywordString: 'string'
250258
// -------------------------------------------------------------------
251259
export type TKeywordStringMapping<Input extends 'string'> = (
@@ -1149,16 +1157,16 @@ export function MappedAsMapping(input: [unknown, unknown] | []): unknown {
11491157
return Guard.IsEqual(input.length, 2) ? [input[1]] : []
11501158
}
11511159
// -------------------------------------------------------------------
1152-
// Mapped: ['{', MappedReadonly, '[', <Ident>, 'in', Type, MappedAs, ']', MappedOptional, ':', Type, '}']
1160+
// Mapped: ['{', MappedReadonly, '[', <Ident>, 'in', Type, MappedAs, ']', MappedOptional, ':', Type, OptionalSemiColon, '}']
11531161
// -------------------------------------------------------------------
1154-
export type TMappedMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]> = (
1155-
Input extends ['{', infer Readonly extends TModifierOperation, '[', infer Key extends string, 'in', infer Union extends T.TSchema, infer As extends T.TSchema[], ']', infer Optional extends TModifierOperation, ':', infer Type extends T.TSchema, '}']
1162+
export type TMappedMapping<Input extends [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]> = (
1163+
Input extends ['{', infer Readonly extends TModifierOperation, '[', infer Key extends string, 'in', infer Union extends T.TSchema, infer As extends T.TSchema[], ']', infer Optional extends TModifierOperation, ':', infer Type extends T.TSchema, null, '}']
11561164
? (As extends [infer As extends T.TSchema]
11571165
? C.TMappedDeferred<T.TIdentifier<Key>, Union, As, TApplyReadonly<Readonly, TApplyOptional<Optional, Type>>>
11581166
: C.TMappedDeferred<T.TIdentifier<Key>, Union, T.TRef<Key>, TApplyReadonly<Readonly, TApplyOptional<Optional, Type>>>
11591167
) : never
11601168
)
1161-
export function MappedMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]): unknown {
1169+
export function MappedMapping(input: [unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown]): unknown {
11621170
return (
11631171
Guard.IsArray(input[6]) && Guard.IsEqual(input[6].length, 1)
11641172
? C.MappedDeferred(T.Identifier(input[3] as string), input[5] as T.TSchema, input[6][0] as T.TSchema, ApplyReadonly(input[1] as TModifierOperation, ApplyOptional(input[8] as TModifierOperation, input[10] as T.TSchema)))
@@ -1508,14 +1516,14 @@ export function ModuleDeclarationListMapping(input: [unknown, unknown]): unknown
15081516
return PropertiesReduce(Delimited(input) as never)
15091517
}
15101518
// -------------------------------------------------------------------
1511-
// ModuleDeclaration: [ExportKeyword, InterfaceDeclarationGeneric | InterfaceDeclaration | TypeAliasDeclarationGeneric | TypeAliasDeclaration]
1519+
// ModuleDeclaration: [ExportKeyword, InterfaceDeclarationGeneric | InterfaceDeclaration | TypeAliasDeclarationGeneric | TypeAliasDeclaration, OptionalSemiColon]
15121520
// -------------------------------------------------------------------
1513-
export type TModuleDeclarationMapping<Input extends [unknown, unknown]> = (
1514-
Input extends [null, infer ModuleDeclaration extends T.TProperties]
1521+
export type TModuleDeclarationMapping<Input extends [unknown, unknown, unknown]> = (
1522+
Input extends [null, infer ModuleDeclaration extends T.TProperties, null]
15151523
? ModuleDeclaration
15161524
: never
15171525
)
1518-
export function ModuleDeclarationMapping(input: [unknown, unknown]): unknown {
1526+
export function ModuleDeclarationMapping(input: [unknown, unknown, unknown]): unknown {
15191527
return input[1] as T.TProperties
15201528
}
15211529
// -------------------------------------------------------------------

0 commit comments

Comments
 (0)