Ensure Function Returns Specific Effect Type Without Direct Annotation

Is there some way to make this function return type Effect<TypePropertyShape, ...> ?

I can directly type-annotate it but than I also need to provide error types and dependencies.

If i don't directly type-annotate my return type is union of types returned by Match:
Effect.Effect<{
    kind: SyntaxKind.StringKeyword;
    optional: boolean;
} | {
    kind: SyntaxKind.NumberKeyword;
    optional: boolean;
} | {
    kind: SyntaxKind.BooleanKeyword;
    optional: boolean;
} | {
    kind: SyntaxKind.TypeReference;
    refName: string;
    optional: boolean;
}, SignatureTypeNodeNotFound | UnsupportedSyntaxKind, never>


code itself:
const buildProperty = Effect.fnUntraced(function* (propertySignature) {
  // ...

  return Match.value<SupportedSyntaxKind>(kind).pipe(
    Match.withReturnType<TypePropertyShape>(),
    Match.when(Match.is(SUPPORTED_SYNTAX_KIND.STRING_KEYWORD), (kind) => ({
      kind,
      optional,
    })),
    Match.when(Match.is(SUPPORTED_SYNTAX_KIND.NUMBER_KEYWORD), (kind) => ({
      kind,
      optional,
    })),
    Match.when(Match.is(SUPPORTED_SYNTAX_KIND.BOOLEAN_KEYWORD), (kind) => ({
      kind,
      optional,
    })),
    Match.when(Match.is(SUPPORTED_SYNTAX_KIND.TYPE_REFERENCE), (kind) => ({
      kind,
      refName: typeNode.getText(),
      optional,
    })),
    Match.exhaustive,
  );
});
Was this page helpful?