Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision 0.34.1 #1080

Merged
merged 5 commits into from
Nov 16, 2024
Merged

Revision 0.34.1 #1080

merged 5 commits into from
Nov 16, 2024

Conversation

sinclairzx81
Copy link
Owner

@sinclairzx81 sinclairzx81 commented Nov 16, 2024

This PR adds a new internal TComputed type which is used to auto dereference computed types on Module import.

TypeBox has two kinds of types. Immediate types (such as TObject, TTuple) and Computed Types (such as TPartial, TOmit). Historically, Computed types could only be passed an Immediate type, where the Computed type performs some action on the Immediate types schematics. However when passing a Ref, the Computed type only sees the Ref, not the Immediate type (meaning the Computed type cannot perform any reasonable action)

With the introduction of Modules. It becomes possible to auto dereference target structures. As of 0.34.1, when passing a Computed type a Ref type, the Computed type will return a deferred TComputed structure which houses the target name of the Computed type, and a TRef containing the target reference.

const Module = Type.Module({

  A: Type.Object({ x: Type.Number() }),

  T: Type.Partial(Type.Ref('A')) // T: TComputed<'Partial', [TRef<'A'>]>
})

The TComputed structure is used internal to the Module to dereference the target Type (with surrounding types), with the Target available via Import.

const T = Module.Import('T')

TypeGuard.IsObject(T.$defs['T']) // True
TypeGuard.IsOptional(T.$defs['T'].properties.x) // True
TypeGuard.IsNumber(T.$defs['T'].properties.x) // True

This PR implements TComputed for

  • Awaited
  • Required
  • Partial
  • KeyOf
  • Omit
  • Pick
  • Record
  • Index

Note: The Index type is known to be cause instantiation problems when used interior to Modules. This will be resolved in subsequent revisions.

@sinclairzx81 sinclairzx81 merged commit 56b760c into master Nov 16, 2024
18 checks passed
@sinclairzx81 sinclairzx81 deleted the ref branch November 16, 2024 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant