Ayushi Verma
Ayushi Verma

Reputation: 241

TS2339: Property 'assign' does not exist on type

I have a file which contains static data as QRCategories and want to send the data as an observable.

The service sending the data is

public qrCodeCategoriesList(): Observable<QRCategoryListResponse> {
    return of (QRCategories);
  }

It is used in component as:

ngOnInit() {
   this.qrCategoryService.qrCodeCategoriesList().subscribe(
     res => {
       this.qrCategories = res;
     }, error => {
       console.log(error);
     }
   );
  }

which works fine but gives an error Property 'assign' does not exist on type in the below line at different component :

  const formData: RegisterData = this.registerForm.value;
  const password2 =   {password2: formData.password1};
  const data = Object.assign({}, formData, password2);

qr-category.ts

import {QRCategoryListResponse} from '../models/qr/qr-category.model';

export const QRCategories: QRCategoryListResponse = {
  count: 10,
  next: null,
  previous: null,
  results: [
    {
      id: 1,
      name: 'Website URL',
    },
    {
      id: 2,
      name: 'Google Maps',
    },
    {
      id: 3,
      name: 'PDF',
    },
    {
      id: 4,
      name: 'Image',
    }
   ]};

Upvotes: 3

Views: 1333

Answers (1)

yanky_cranky
yanky_cranky

Reputation: 1363

Here, try using following :

const data=(<any>Object).assign(formData, password2)

or

data={...formData,...password2};

Make sure this will copy by reference nested objects, so use deep copy instead with library like Lodash, or :

JSON.parse(JSON.stringify(someData));

Upvotes: 3

Related Questions