Alorel / shrink-ray

Node.js compression middleware
MIT License
177 stars 16 forks source link

Types: ShrinkRayOptions.filter should be optional #52

Open karol-majewski opened 4 years ago

karol-majewski commented 4 years ago

Hello and thank you for your work.

I noticed that when I want to pass some options, I'm required to provide filter even when I have no custom filter to provide.

Offending code

app.use(
  shrinkRay({
    brotli: {
      mode: 11,
    },
  }),
);

Error message:

Argument of type '{ brotli: { mode: number; }; }' is not assignable to parameter of type 'ShrinkRayOptions'.
  Property 'filter' is missing in type '{ brotli: { mode: number; }; }' but required in type 'ShrinkRayOptions'.ts(2345)

Workaround

I could do this:

app.use(
  shrinkRay({
    brotli: {
      mode: 11,
    },
    filter: shrinkRay.filter,
  }),
);

but it strikes me as awkward and slightly redundant since adding filter: shrinkRay.filter doesn't affect the functionality in any way.

Solution

This: https://github.com/Alorel/shrink-ray/blob/f7cfcc7d5cf5d31ed8deadbfd717f80e64585a8c/index.d.ts#L17

should be changed to:

- interface ShrinkRayOptions extends Filterable {
+ interface ShrinkRayOptions extends Partial<Filterable> {

What do you think?