-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Inference for Required and Partial
- Loading branch information
1 parent
4dadbe8
commit 7855086
Showing
3 changed files
with
25 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import { TypeSystem } from '@sinclair/typebox/system' | ||
import { TypeCompiler } from '@sinclair/typebox/compiler' | ||
import { Value, ValueGuard } from '@sinclair/typebox/value' | ||
import { Type, TypeGuard, Kind, Static, TSchema, KeyResolver, TObject, TypeRegistry, StaticDecode } from '@sinclair/typebox' | ||
import { Benchmark } from './benchmark' | ||
|
||
// Todo: Investigate Union Default (initialize interior types) | ||
// Todo: Implement Value.Clean() Tests - Done | ||
|
||
export function Parse<T extends TSchema>(schema: T, value: unknown): StaticDecode<T> { | ||
const converted = Value.Convert(schema, value) | ||
const defaulted = Value.Default(schema, converted) | ||
const decoded = Value.Decode(schema, defaulted) | ||
return Value.Clean(schema, decoded) | ||
} | ||
import { Type, Static } from '@sinclair/typebox'; | ||
|
||
export const A = Type.Object({ | ||
a: Type.ReadonlyOptional(Type.Number()), | ||
b: Type.Readonly(Type.Number()), | ||
c: Type.Optional(Type.Number()), | ||
d: Type.Number() | ||
}) | ||
const B = Type.Required(A) | ||
const C = Type.Partial(A) | ||
|
||
type A = Static<typeof A> | ||
type B = Static<typeof B> | ||
type C = Static<typeof C> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters