connor4312 / cockatiel

🐦 A resilience and fault-handling library. Supports Backoffs, Retries, Circuit Breakers, Timeouts, Bulkhead Isolation, and Fallbacks.
MIT License
1.59k stars 50 forks source link

Optional properties on IExponentialBackoffOptions should be marked as optional #6

Closed xzyfer closed 4 years ago

xzyfer commented 4 years ago

Currently trying to do the following

.exponential({ maxDelay: 1000, initialDelay: 10, maxAttempts: 2 })

Results in the following error

Argument of type '{ maxDelay: number; initialDelay: number; maxAttempts: number; }' is not assignable to parameter of type 'IExponentialBackoffOptions<IRetryBackoffContext<unknown>>'.
  Type '{ maxDelay: number; initialDelay: number; maxAttempts: number; }' is missing the following properties from type 'IExponentialBackoffOptions<IRetryBackoffContext<unknown>>': generator, exponent

However the ExponentialBackoff constructor merges the supplied options with the a default set of options. This means all properties on IExponentialBackoffOptions are optional.

xzyfer commented 4 years ago

Additionally when trying to satisfy the interface with the defaultOptions from ExponentialBackoff

.exponential({
    generator: decorrelatedJitterGenerator,
    maxDelay: 30000,
    maxAttempts: Infinity,
    exponent: 2,
    initialDelay: 128,
});

Results in the following error

Type 'GeneratorFn<[number, number]>' is not assignable to type 'GeneratorFn<IRetryBackoffContext<unknown>>'.
  Type '[number, number]' is not assignable to type 'IRetryBackoffContext<unknown>'.
connor4312 commented 4 years ago

Thanks, fixed in f96beb5 and published in 0.1.2.