question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Regression - Array.filter

See original GitHub issue

Bug Report

Array filter have possibly wrong signature or 4.8 introduced “Unconstrained Generics No Longer Assignable to {}” introduced type error

🔎 Search Terms

image

🕗 Version & Regression Information

After the update to 4.8.2

⏯ Playground Link

Playground - long cause copy some angular types for perfect reproduction - actual code on the end of code

💻 Code

export const serializeParams = <T extends {}>(query: T): HttpParams => {
  return new HttpParams().appendAll(
        Object.fromEntries(Object.entries(query))
        )
};


export const serializeParams2 = <T extends {}>(query: T): HttpParams => {
      return new HttpParams().appendAll(
        Object.fromEntries(Object.entries(query).filter(val => val[1] !== undefined))
    )
};


export const serializeParams3 = <T extends {}>(query: T): HttpParams => {
  return new HttpParams().appendAll(Object.fromEntries(Object.entries(query)
    .filter(([_, value]) => value !== undefined)
    .map(([key, value]) => {
      if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
        return [key, JSON.stringify(value)];
      } else {
        return [key, value ?? ''];
      }
    })));
};


export const serializeParams4 = <T extends {}>(query: T): HttpParams => {
  const entries = Object.entries(query)
    .filter(([_, value]) => value !== undefined)
    .map(([key, value]) => {
      if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
        return [key, JSON.stringify(value)];
      } else {
        return [key, value ?? ''];
      }
    });

  return new HttpParams().appendAll(Object.fromEntries(entries)); // here very weird - moving body to separate const fixes type error in VS code but build still fails with error
};

🙁 Actual behavior

unfiltered and filtered arrays behave differently

🙂 Expected behavior

unfiltered and filtered arrays behave the same

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
jcalzcommented, Aug 31, 2022

🔎 Search Terms

This should probably be replaced with a list of terms people can search for to find this issue and related issues.

0reactions
graphemeclustercommented, Sep 1, 2022

@MartinJohns Yes, I can confirm that. All the versions I tried raise the same error. I didn’t agree with the OP either. (I am just a passer-by.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript filter array by data from another - Stack Overflow
And I have an array with ids [1, 3, 5],. How can I filter the array object to leave records only with id's...
Read more >
statsmodels.regression.recursive_ls.RecursiveLS.filter
Array of parameters at which to evaluate the loglikelihood function. transformedbool, optional. Whether or not params is already transformed. Default is True ...
Read more >
Array.prototype.filter() - JavaScript - MDN Web Docs
The filter() method creates a shallow copy of a portion of a given array, filtered down to just the elements from the given...
Read more >
Should You Use .includes or .filter to Check if An Array ...
If you need to know if a JavaScript array contains an item, you have a couple of options other than just writing a...
Read more >
Filter disturbances through regression model with ARIMA errors
This MATLAB function filters errors to produce responses, innovations, and unconditional disturbances of a univariate regression model with ARIMA time ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found