The assignment to 'GetUserByIdModel' is invalid because it is not a variable

I encounter an issue while attempting to populate a particular model, receiving the error "Cannot assign to 'GetUserByIdModel' because it is not a variable."

Here is the model in question:

export class GetUserByIdModel {
  firstname: string;
  lastname: string;
  nationalityId: number;
  identityTypeId: number;
  identityValue: string;
  titleId: number;
  genderId: number;
  contactChannels: Array<ContactChannel>;
}

export class ContactChannel {
  type: number;
  value: string;
}

After importing the model into a service file, I encounter issues with its usage.

Declarations:

userDetails: GetUserByIdModel;

Function:

  getUserDetails(userId): Observable<GetUserByIdModel> {l
    const token = this._storeService.getStoredData().id_token;
    const headers = new HttpHeaders()
      .set('Authorization', `Bearer ${token}`)
      .set('Content-Type', 'application/json');
    const options = { headers: headers };
    const url = `${this.candidateUrl}/Get/${userId}`;
    this._http.get<any>(url, options).subscribe((resp) => {
    this.userDetails: GetUserByIdModel = {
      firstname: resp.firstname,
      lastname: resp.lastname,
      nationalityId: resp.firstname,
      identityTypeId: resp.identityTypeId,
      identityValue: resp.identityValue,
      titleId: resp.titleId,
      genderId: resp.genderId,
      contactChannels: [
        { type: 1, value: resp[0].value },
        { type: 2, value: resp[1].value }
      ],
    };
  })

    return new Observable((observer) => {
      observer.next(this.userDetails);
      observer.complete();
    });
  }

The error point is specifically on this line

this.userDetails: GetUserByIdModel = {...

Your assistance would be greatly appreciated

Answer №1

Eliminate the reference to type from

this.userDetails: GetUserByIdModel -> this.userDetails = {..}
as it is redundant and ensure that the fields firstName?, lastName? are set to nullable...

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

Tips for importing bootstrap scss efficiently in an angular project to prevent style duplication

Is there a way to optimize an Angular project for utilizing Bootstrap's mixins and variables without constantly importing the styles in every component? Currently, the project I'm working on imports the variables.scss file multiple times due to u ...

What is the method for updating a property in an object of a Typescript class?

I am trying to work with a Fruit class: export class Fruit { constructor(public id: number, public name: string) {} public changeName(_name: string): void { console.log('changing name') this.name = _name } } My imple ...

Updating Facebook meta tags dynamically in Angular 4 to enhance Open Graph integration

Is there a way to dynamically update meta tags for Facebook/Whatsapp share dialog? I recently upgraded my angular 2 application to angular 4 in order to utilize the Meta service and update meta tags dynamically once data is retrieved from an API. Within ...

Extending an External Object with Custom Properties in TypeScript

When working with an external library, I often find myself needing to add new properties to passed-in parameters. Instead of using (<any>conv.data) due to the compiler error Object is of type 'unknown', I'm curious if there's a mo ...

regex execution and testing exhibiting inconsistent behavior

The regex I am using has some named groups and it seems to match perfectly fine when tested in isolation, but for some reason, it does not work as expected within my running application environment. Below is the regex code that works everywhere except in ...

Is there a way to configure side={THREE.BackSide} using an external .glb file?

As a beginner in Threejs, I am trying to incorporate the use of side="THREE.BackSide" with an external model file named room.glb. My development environment consists of nextjs 13 (with typescript and app directory enabled) along with @react-three ...

The NestJS server encounters an unhandled exception leading to a server

As a newcomer to Nest.js and in the process of building a REST API server with typeorm, I have encountered an issue related to async functions. If I forget to include the await keyword while using an async function, it may result in an exception like &apos ...

It seems that an error has occurred: DOMException was thrown because the attempt to run 'importScripts' on 'WorkerGlobalScope' has failed. The script located at 'http://localhost:4200/BlinkCardWasmSDK.js' was unable to load properly

Recently, I attempted to integrate this credit card reader into my Angular application. Despite carefully following all the installation steps and obtaining a valid license key, I encountered the following error: Error during the initialization of the SDK! ...

Typescript with Mongoose: I am currently attempting to separate schema, methods, and statics into different files. However, I am facing an issue where the types are set to '

Currently, I am in the process of breaking down my single-file Mongoose schemas with statics and methods. I stumbled upon a helpful tutorial for organizing this structure: here. As someone new to TypeScript, I am already experiencing the benefits it brings ...

Collaborate on sharing CSS and TypeScript code between multiple projects to

I am looking for a solution to efficiently share CSS and TS code across multiple Angular projects. Simply copy-pasting the code is not an ideal option. Is there a better way to achieve this? ...

What is the best way to incorporate Firebase into an Angular 2 TypeScript application without relying on AngularFire?

What is the best way to integrate Firebase into an Angular 2 TypeScript application without relying on AngularFire? I have a simple Angular 2 application and I am looking to incorporate Firebase into it. ...

Encountering an error when implementing a router object within a TypeScript class in a Node.js environment

I have a Node.js service written in TypeScript. I am currently working on implementing a separate routing layer within the application. In my app.js file, I have the following code: let IndividualRoute= require('./routing/IndividualRoute'); app ...

Opening a Bootstrap tab programmatically in Angular

I had a previous experience where I had to programmatically open a modal. Take a look at this snippet of code that represents the modal: <div class="modal fade" id="messageModal" tabindex="-1" role="dialog">< ...

A guide on triggering a function in Angular 6 when scrolling up or down

Is there a way to trigger a function when a user scrolls up or down in an Angular 6 project? I want to implement a feature similar to fullpage.js in my Angular 6 application. I initially attempted to achieve this using Angular animations, but without succ ...

Securing pathways in Next.js using middleware and Next-Auth

Hey there, I'm currently working on adding some route protection in NextJS using middleware for authentication with next-auth. According to the documentation, this is what my middleware.ts file should look like: export { default } from "next-auth ...

From broad to specialized category

My goal is to inherit a class and modify its dynamic type to collapse into a specific type (from T to Person). In order to demonstrate this, I have created some dummy classes: class Person { constructor(public name: string){} } class Base<T> { ...

Exploring the capabilities of using Next.js with grpc-node

I am currently utilizing gRPC in my project, but I am encountering an issue when trying to initialize the service within a Next.js application. Objective: I aim to create the client service once in the application and utilize it in getServerSideProps (wit ...

How to vertically align radio buttons with varying label lengths using Angular and Bootstrap 4?

Is there a way to properly align radio buttons with variable length labels? When each label has a different length, the radio buttons appear misaligned. How can this be fixed? <div class="row"> <div class="form-check form-check-inline" *ngFor="l ...

Pairing objects by utilizing a Universal Mapper

Classes Defined: abstract class ModelBase { id: string; } class Person extends ModelBase { favoriteDog: Dog | undefined; favoriteDogId: string | undefined; dogs: Dog[] } class Dog extends ModelBase { id: string; ownerId: string; name: strin ...

Angular Material's floating label feature disrupts the form field's outline styling

Whenever I try to change the appearance of the form field to outline, the floating label ends up breaking the outline. Here is a code snippet for reference: <mat-form-field appearance="outline"> <mat-label>Password&l ...