TS2339 Error: The 'json' property is not found on the 'Object' type. Are there any properties related to 'json' in the Observable type?

I keep receiving a compilation error:

TS2339: Property 'json' does not exist on type 'Object'
when attempting to map JSON onto a complex object Model.SearchResult.RootObject. The error occurs within the res.json() method of the following service:

import { Injectable } from '@angular/core';
import { ResultPrice } from '../models/result-prices.model';
import { BaseService } from '../shared-components/base-service/base.service';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs/Rx';
import * as Model from '../models/results.model';
import { HttpClient } from '@angular/common/http';
import 'rxjs/add/operator/map';


@Injectable()
export class SearchResultService {
    private apiUrl = 'http://someurl/api/SearchResult/';


    constructor(public http: HttpClient ) {
    }

    getSearchResultTable(hash: number): Observable<Model.SearchResult.RootObject> {
        let tmp = this.http.get('http://someurl/api/SearchResult/123')
        .map(res => {
            return res.json().results.map(item => {
                return new Model.SearchResult.RootObject();
          });
        });
        return tmp;
    }
}

Does the Observable interface actually contain a json property? Could it be that I missed importing something?

Answer №1

If you want to add a type to the first argument of the map function in your code snippet, you can do it like this:

return this.http.get('http://someurl/api/SearchResult/123')
  .map(res: any) => {
    return res.json().results.map(item => {
      return new Model.SearchResult.RootObject();
    });
  });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Retrieve information from a nearby dataset

I have encountered an issue while developing a mobile app in qx and I am seeking assistance. In the application.js, I am fetching JSON data from a server using qx.store.json(url). This JSON data is then used to create a model that is bound to an offline mo ...

Building an Event Scheduler in Outlook Calendar with Angular 5

Currently, I am utilizing Angular version 5.2 for a room booking portal project. One of the requirements entails adding an event to the Outlook calendar on the day a room is booked. The system includes a table listing all bookings, with a button in each ro ...

Determining if an item is empty, undefined, or null in Angular: a guide

I received a .json file structured as data [0 ... n]. Each position in the data array contains an object with various attributes, such as: {photo1, photo2, photo3 ... photoN} For a visual representation of how the json file is formatted, you can check ...

Eslint is actively monitoring files specified in the eslintignore to ensure they meet the set

I am currently working on a TypeScript project that is bundled by Webpack. I want to integrate Eslint into the project, but I have encountered an issue where Eslint watches compiled files even if they are listed in the .eslintignore file. .eslintignore: . ...

Finding a solution to the type issue of error handling in Route Handler with NextJS

I'm working on a route handler located at app/api/transactions/route.ts. Here's a snippet of the code: import { NextRequest, NextResponse } from "next/server"; import { AxiosError } from "axios"; import axios from "../axi ...

The parameter type '==="' cannot be assigned to the 'WhereFilterOp' type in this argument

I'm currently working on creating a where clause for a firebase collection reference: this.allItineraries = firebase .firestore() .collection(`itinerary`); Here is the issue with the where clause: return this.allItiner ...

The correct method for sending an array to a shader in three.js

In my current project, I have a straightforward program in which I am attempting to pass an array of predefined values (essentially serving as a lookup table) to a shader. The corresponding code snippet looks like this: var table = []; for ( var ...

In C++, converting a string to a const char pointer can sometimes result in garbage characters being added

I am facing an issue with a struct that needs to retain a const char * value for later use, but the string gets destroyed in the process. Below is the code snippet I have been working on: HttpRequest* send(string reply) { int len = str ...

The access to the HTTP response object is not possible: the property is not found on the Object type

I recently created a response object and assigned it to the "this" object. However, when I try to access the datacentersinfo property, I encounter an error stating that the property does not exist on type Object. Due to this issue, I am unable to generat ...

Obtaining the current row index in React MUI Data Grid using React-Context

Scenario In my application, I have implemented an MUI Data Grid with custom components in each row: RowSlider, RowDate, and RowLock using the MUI Components Slider, Date Picker, and Button respectively. View the Data Grid Visualization The Slider and Da ...

Set up linter rules that utilize `useEffect` in place of `React.useEffect` (utilizing named export rather than full export)

It's important in our codebase to always use: import { useEffect } from 'react'; instead of: import React from 'react'; // use in code as `React.useEffect` Can we enforce this rule with longer eslint rules? If so, how can we impl ...

Set the GridToolbarQuickFilter text box to have an outlined style in Material UI v5

How can I customize the appearance of the GridToolbarQuickFilter textbox, such as outlining it? Ideally, I would like to accomplish this through theme.tsx, but I am open to any suggestions. https://i.stack.imgur.com/H1Ojj.png I have experimented with var ...

Identifying when an element is in or out of view using Next.js and TypeScript

I'm currently working on an app using Next and Typescript. The app features a navigation bar at the top of the screen, and I need it to change its style once it reaches a certain point in the view. I attempted to use jQuery for this purpose, but encou ...

Assassin eradicated from list of cast members

In my quest to select a killer from the Cast Members Array for the game, I want the function to pick one person as the killer and then remove them from the castMember player array. Once the killer is chosen, they should be removed from the survivors array ...

Whenever signing in with Next Auth, the response consistently exhibits the values of "ok" being false and "status" being 302, even

I am currently using Next Auth with credentials to handle sign-ins. Below is the React sign-in function, which can be found at this link. signIn('credentials', { redirect: false, email: email, password: password, ...

Leveraging Express Mergeparams in TypeScript

I've run into an issue while working on my small project in Typescript. The problem arises when I attempt to nest my router, as Typescript doesn't seem to acknowledge the parent's parameter. Within the "child" file, I have the following cod ...

"Discover the power of Next.js by utilizing dynamic routes from a curated list

I am working on a Next.js application that has a specific pages structure. My goal is to add a prefix to all routes, with the condition that the prefix must be either 'A', 'B', or 'C'. If any other prefix is used, it should re ...

Compiling the configureStore method with the rootreducer results in compilation failure

Software Setup @angular/cli version: ^9.1.2 System Details NodeJS Version: 14.15.1 Typescript Version: 4.0.3 Angular Version: 10.1.6 @angular-redux/store version: ^11.0.0 @angular/cli version (if applicable): 10.1.5 OS: Windows 10 Expected Outcome: ...

When attempting to start npm, Angular2 fails to recognize a specific module

I recently installed a new module and added it to my system JS configuration as follows: // specifying where to look for things using the map object var map = { 'angular2-notifications': 'node_modules/angular2-notifications', } ...

Enabling Event bus suggestions for Typescript: A step-by-step guide

Hello, I've encountered an issue while attempting to add types for the TinyEmitter library. Specifically, I need to define two methods. First: addEventListener(e: string, (...args: any[]) => void): void; Second: emit(e: string, ...args: any[]): vo ...