Skip to content

Revision 0.34.27#1182

Merged
sinclairzx81 merged 4 commits intomasterfrom
transform
Feb 20, 2025
Merged

Revision 0.34.27#1182
sinclairzx81 merged 4 commits intomasterfrom
transform

Conversation

@sinclairzx81
Copy link
Copy Markdown
Owner

This PR enables Transforms to be embedded within Module types. The updates include new inference paths for StaticDecode as well as updates to TComputed inference to rewrite the Transform signature (Ref(C)) to the reference target. This makes Transforms a form TComputed.

const Z = Type.Module({
  A: Type.String(),
  // └─────────┐
  B: Type.Ref('A'),
  // └─────────┐
  C: Type.Ref('B'),
  // └────────────────────────┐
  T: Type.Transform(Type.Ref('C'))
    .Decode((value) => parseInt(value as string)) // requires as assertion interior to module
    .Encode((value) => value.toString()),
  // └─────────┐
  X: Type.Ref('T'),
  // └─────────┐
  Y: Type.Ref('X'),
  // └─────────┐
  Z: Type.Ref('Y'),
  // └─────┐
}).Import('Z')

Expect(Z).ToStaticDecode<number>()
Expect(Z).ToStaticEncode<string>()

Using Transforms wrapped Ref types require type assertion as it's not possible to infer the reference target interior to the module.

@sinclairzx81 sinclairzx81 merged commit 5130ee5 into master Feb 20, 2025
@sinclairzx81 sinclairzx81 deleted the transform branch February 20, 2025 07:24
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