Skip to content

TS[5.7] Optimize Function Composition Using Variadic Tuple Types #221

@MaryamAdnan3

Description

@MaryamAdnan3

Problem:

Currently, function composition manually chains interceptors, making it difficult to scale.

Proposed Solution:

Refactor function composition to use variadic tuple types for better flexibility and readability.

TypeScript Version Required: 5.7+

Example Fix (httpInterceptor.ts):

export function applyInterceptors<T>(
  ...interceptors: HttpInterceptorInterface<T>[]
): HttpCallExecutor<T> {
  return (request, options, client) =>
    interceptors.reduceRight(
      (next, interceptor) => (req, opts) => interceptor(req, opts, next),
      client
    )(request, options);
}

Affected Files:

  • httpInterceptor.ts
  • apiLogger.ts

Expected Benefits:

  • Reduces boilerplate code for chaining functions.
  • Improves scalability by allowing flexible function composition.

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions