Skip to content

Commit e54b5e1

Browse files
authored
Version 1.1.18 (#1565)
* Use Static Return Annotation on Value Functions * ChangeLog * Version
1 parent 7e2c3a5 commit e54b5e1

13 files changed

Lines changed: 375 additions & 78 deletions

File tree

changelog/1.1.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.1.18](https://github.com/sinclairzx81/typebox/pull/1565)
7+
- Use Explicit Static Return Type Annotation for Value Functions
68
- [Revision 1.1.17](https://github.com/sinclairzx81/typebox/pull/1564)
79
- Use Function Cache Optimization for JIT
810
- [Revision 1.1.16](https://github.com/sinclairzx81/typebox/pull/1562)

src/value/assert/assert.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ THE SOFTWARE.
2626
2727
---------------------------------------------------------------------------*/
2828

29+
// deno-fmt-ignore-file
30+
2931
import { Arguments } from '../../system/arguments/index.ts'
3032
import type { TLocalizedValidationError } from '../../error/index.ts'
3133
import type { Static, TProperties, TSchema } from '../../type/index.ts'
@@ -49,11 +51,9 @@ export class AssertError extends Error {
4951
}
5052
}
5153
/** Asserts the a value matches the given type. This function returns a TypeScript type asserts predicate and will throw AssertError if value does not match. */
52-
export function Assert<Context extends TProperties, const Type extends TSchema, Result extends unknown = Static<Type, Context>>(context: Context, type: Type, value: unknown): asserts value is Result
53-
54+
export function Assert<const Type extends TSchema>(type: Type, value: unknown): asserts value is Static<Type>
5455
/** Asserts the a value matches the given type. This function returns a TypeScript type asserts predicate and will throw AssertError if value does not match. */
55-
export function Assert<const Type extends TSchema, Result extends unknown = Static<Type>>(type: Type, value: unknown): asserts value is Result
56-
56+
export function Assert<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): asserts value is Static<Type, Context>
5757
/** Asserts the a value matches the given type. This function returns a TypeScript type asserts predicate and will throw AssertError if value does not match. */
5858
export function Assert(...args: unknown[]): void {
5959
const [context, type, value] = Arguments.Match<[TProperties, TSchema, unknown]>(args, {

src/value/check/check.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ import type { Static, TProperties, TSchema } from '../../type/index.ts'
3333
import { Check as SchemaCheck } from '../../schema/index.ts'
3434

3535
/** Checks a value matches the provided type. */
36-
export function Check<const Type extends TSchema,
37-
Result extends unknown = Static<Type>
38-
>(type: Type, value: unknown): value is Result
39-
36+
export function Check<const Type extends TSchema>(type: Type, value: unknown): value is Static<Type>
4037
/** Checks a value matches the provided type. */
41-
export function Check<Context extends TProperties, const Type extends TSchema,
42-
Result extends unknown = Static<Type, Context>
43-
>(context: Context, type: Type, value: unknown): value is Result
44-
38+
export function Check<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): value is Static<Type, Context>
4539
/** Checks a value matches the provided type. */
4640
export function Check(...args: unknown[]): unknown {
4741
const [context, type, value] = Arguments.Match<[TProperties, TSchema, unknown]>(args, {

src/value/codec/decode.ts

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,32 +75,11 @@ const Decoder = Pipeline([
7575
// ------------------------------------------------------------------
7676
// Decode
7777
// ------------------------------------------------------------------
78-
/**
79-
* Decodes a value against the given type by applying a sequence of Clone,
80-
* Default, Convert, and Clone operations, then executing any embedded Decode
81-
* callbacks. If the processing sequence fails to produce a value matching the
82-
* provided type, a DecodeError is thrown.
83-
*/
84-
export function Decode<const Type extends TSchema,
85-
Result extends unknown = StaticDecode<Type>
86-
>(type: Type, value: unknown): Result
87-
88-
/**
89-
* Decodes a value against the given type by applying a sequence of Clone,
90-
* Default, Convert, and Clone operations, then executing any embedded Decode
91-
* callbacks. If the processing sequence fails to produce a value matching the
92-
* provided type, a DecodeError is thrown.
93-
*/
94-
export function Decode<Context extends TProperties, const Type extends TSchema,
95-
Result extends unknown = StaticDecode<Type, Context>
96-
>(context: Context, type: Type, value: unknown): Result
97-
98-
/**
99-
* Decodes a value against the given type by applying a sequence of Clone,
100-
* Default, Convert, and Clone operations, then executing any embedded Decode
101-
* callbacks. If the processing sequence fails to produce a value matching the
102-
* provided type, a DecodeError is thrown.
103-
*/
78+
/** Decodes a value with the given type. */
79+
export function Decode<const Type extends TSchema>(type: Type, value: unknown): StaticDecode<Type>
80+
/** Decodes a value with the given type. */
81+
export function Decode<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): StaticDecode<Type, Context>
82+
/** Decodes a value with the given type. */
10483
export function Decode(...args: unknown[]): never {
10584
const [context, type, value] = Arguments.Match<[TProperties, TSchema, unknown]>(args, {
10685
3: (context, type, value) => [context, type, value],

src/value/codec/encode.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,11 @@ const Encoder = Pipeline([
7575
// ------------------------------------------------------------------
7676
// Encode
7777
// ------------------------------------------------------------------
78-
/** Encodes a value. */
79-
export function Encode<const Type extends TSchema,
80-
Result extends unknown = StaticEncode<Type>
81-
>(type: Type, value: unknown): Result
82-
83-
/** Encodes a value. */
84-
export function Encode<Context extends TProperties, const Type extends TSchema,
85-
Result extends unknown = StaticEncode<Type, Context>
86-
> (context: Context, type: Type, value: unknown): Result
87-
88-
/** Encodes a value. */
78+
/** Encodes a value with the given type. */
79+
export function Encode<const Type extends TSchema>(type: Type, value: unknown): StaticEncode<Type>
80+
/** Encodes a value with the given type. */
81+
export function Encode<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): StaticEncode<Type, Context>
82+
/** Encodes a value with the given type. */
8983
export function Encode(...args: unknown[]): never {
9084
const [context, type, value] = Arguments.Match<[TProperties, TSchema, unknown]>(args, {
9185
3: (context, type, value) => [context, type, value],

src/value/convert/convert.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ import { FromType } from './from-type.ts'
3838
* provided value. If mutation is not wanted, you should Clone the value before passing to this function.
3939
*/
4040
export function Convert(context: TProperties, type: TSchema, value: unknown): unknown
41-
4241
/**
4342
* Converts a value to the given type, coercing interior values if a reasonable conversion is possible. This
4443
* function returns unknown so callers should Check the return value before use. This function mutates the
4544
* provided value. If mutation is not wanted, you should Clone the value before passing to this function.
4645
*/
4746
export function Convert(type: TSchema, value: unknown): unknown
48-
4947
/**
5048
* Converts a value to the given type, coercing interior values if a reasonable conversion is possible. This
5149
* function returns unknown so callers should Check the return value before use. This function mutates the

src/value/create/create.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,9 @@ import type { TProperties, TSchema, Static } from '../../type/index.ts'
3333
import { FromType } from './from-type.ts'
3434

3535
/** Creates a value from the provided type. This function will use `default` annotations if present. */
36-
export function Create<const Type extends TSchema,
37-
Result extends unknown = Static<Type>
38-
>(type: Type): Result
39-
36+
export function Create<const Type extends TSchema>(type: Type): Static<Type>
4037
/** Creates a value from the provided type. This function will use `default` annotations if present. */
41-
export function Create<const Context extends TProperties, Type extends TSchema,
42-
Result extends unknown = Static<Type, Context>
43-
>(context: Context, type: Type): Result
44-
38+
export function Create<const Context extends TProperties, Type extends TSchema>(context: Context, type: Type): Static<Type, Context>
4539
/** Creates a value from the provided type. This function will use `default` annotations if present. */
4640
export function Create(...args: any[]): unknown {
4741
const [context, type] = Arguments.Match<[TProperties, TSchema]>(args, {

src/value/default/default.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ import { FromType } from './from-type.ts'
3838
* provided value. If mutation is not wanted, you should Clone the value before passing to this function.
3939
*/
4040
export function Default(type: TSchema, value: unknown): unknown
41-
4241
/**
4342
* Patches missing properties on the value using default annotations specified on the provided type. This
4443
* function returns unknown so callers should Check the return value before use. This function mutates the
4544
* provided value. If mutation is not wanted, you should Clone the value before passing to this function.
4645
*/
4746
export function Default(context: TProperties, type: TSchema, value: unknown): unknown
48-
4947
/**
5048
* Patches missing properties on the value using default annotations specified on the provided type. This
5149
* function returns unknown so callers should Check the return value before use. This function mutates the

src/value/parse/parse.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@ export const Parser = Pipeline([
6565
(context, type, value) => Assert(context, type, value)
6666
])
6767
/** Parses a value with the given type. */
68-
export function Parse<const Type extends TSchema,
69-
Result extends unknown = StaticParse<Type>
70-
>(type: Type, value: unknown): Result
71-
68+
export function Parse<const Type extends TSchema>(type: Type, value: unknown): StaticParse<Type>
7269
/** Parses a value with the given type. */
73-
export function Parse<Context extends TProperties, const Type extends TSchema,
74-
Result extends unknown = StaticParse<Type, Context>
75-
>(context: Context, type: Type, value: unknown): Result
76-
70+
export function Parse<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): StaticParse<Type, Context>
7771
/** Parses a value with the given type. */
7872
export function Parse(...args: unknown[]): never {
7973
const [context, type, value] = Arguments.Match<[TProperties, TSchema, unknown]>(args, {

src/value/repair/repair.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,15 @@ import { Assert } from '../assert/index.ts'
4040
* default structures derived from the type. If the value already conforms to the type, no
4141
* action is performed.
4242
*/
43-
export function Repair<const Type extends TSchema,
44-
Result extends unknown = Static<Type>
45-
>(type: Type, value: unknown): Result
46-
43+
export function Repair<const Type extends TSchema>(type: Type, value: unknown): Static<Type>
4744
/**
4845
* Repairs a value to match the provided type. This function is intended for data migration
4946
* scenarios where existing values need to be migrating to an updated type. This function will
5047
* repair partially mismatched values by populating missing sub-properties and elements with
5148
* default structures derived from the type. If the value already conforms to the type, no
5249
* action is performed.
5350
*/
54-
export function Repair<Context extends TProperties, const Type extends TSchema,
55-
Result extends unknown = Static<Type, Context>
56-
>(context: Context, type: Type, value: unknown): Result
57-
51+
export function Repair<Context extends TProperties, const Type extends TSchema>(context: Context, type: Type, value: unknown): Static<Type, Context>
5852
/**
5953
* Repairs a value to match the provided type. This function is intended for data migration
6054
* scenarios where existing values need to be migrating to an updated type. This function will

0 commit comments

Comments
 (0)