0

I'm following the following link and it SHOULD work!

LoDash: Get an array of values from an array of object properties

This is the CODE that should work

_.map(users, 'id'); // [12, 14, 16, 18]

Here's what the example is for the above solution

const users = [{
      id: 12,
      name: 'Adam'
   },{
      id: 14,
      name: 'Bob'
   },{
      id: 16,
      name: 'Charlie'
   },{
      id: 18,
      name: 'David'
   }
]

Here's my JSON object... it's the entire ZIPCODE, CITY, STATE, COUNTY US Postal Service DB and it's 349,000+ lines of JSON formatted.

This is only a small snippet... and is called: citystatezip

import * as citystatezip from 'src/assets/json/city-state-zip-county.json';

The resulting JSON for the above...

[
  {
    "zip_code": 43616,
    "latitude": 41.656948,
    "longitude": -83.44433,
    "city": "Oregon",
    "state": "OH",
    "county": "Lucas"
  },
  {
    "zip_code": 43617,
    "latitude": 41.66765,
    "longitude": -83.722437,
    "city": "Toledo",
    "state": "OH",
    "county": "Lucas"
  },
  {
    "zip_code": 43618,
    "latitude": 41.656948,
    "longitude": -83.399129,
    "city": "Oregon",
    "state": "OH",
    "county": "Lucas"
  }
]

all my code is doing is PULLING the JSON object from a file:

  getAllZipCodes(): any {
    // this is NOT an error
    this.allzipcodes = _.map(citystatezip, 'zip_code');
  }

BUT, the error I'm getting for _.map is in the picture and shown below.

import citystatezip
No overload matches this call.
  The last overload gave the following error.
    Argument of type '{}' is not assignable to parameter of type 'Dictionary<unknown> | NumericDictionary<unknown> | null | undefined'.ts(2769)
collection.d.ts(1180, 9): The last overload is declared here.

The error I'm getting with LODASH _.map

Peter The Angular Dude
  • 1,112
  • 5
  • 26
  • 53

0 Answers0