Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Argument of type '{ filepath: string; webviewPath: string; }' is not assignable to parameter of type 'Photo'

so im trying to build the photo-gallery sample project for ionic and im stuck on this error. not sure what i means really. i tried downgrading npm package. didnt work. all the other questions kinda just confuse me more lol so here is the full error:

error TS2345: Argument of type '{ filepath: string; webviewPath: string; }' is not assignable to parameter of type 'Photo'. [ng] Object literal may only specify known properties, and 'filepath' does not exist in type 'Photo'.

like image 748
stackoverflowrog Avatar asked Oct 25 '25 12:10

stackoverflowrog


1 Answers

I believe they made a mistake in the tutorial. They give the interface the same name as the Photo import from '@capacitor/camera'. Instead, give the interface the name 'UserPhoto'.

My source is looking at the ionic repository for this project on GitHub: https://github.com/ionic-team/tutorial-photo-gallery-angular

You need to change the following in the photo.service.ts file:

export interface UserPhoto {
  filepath: string;
  webviewPath: string;
}

This is at the bottom of the file, outside of the PhotoService class definition.

You also need to define an array of type UserPhoto, not Photo in your PhotoService method. This looks like this:

export class PhotoService {
  
  public photos: UserPhoto[] = [];
like image 125
Ed Walpole Avatar answered Oct 28 '25 03:10

Ed Walpole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!