简体   繁体   中英

Ionic : Typescript Error

I am new to Ionic and I am facing this issue when I run build command. $ ionic cordova build android

[00:34:40]  typescript: src/pages/becomevendor/becomevendor.ts, line: 97 
        Argument of type '(result: NativeGeocoderReverseResult) => void' is not assignable to parameter of type 
        '(value: NativeGeocoderReverseResult[]) => void | PromiseLike<void>'. Types of parameters 'result' and 
        'value' are incompatible. Type 'NativeGeocoderReverseResult[]' is not assignable to type 
        'NativeGeocoderReverseResult'. Property 'countryCode' is missing in type 'NativeGeocoderReverseResult[]'. 

  L96:  this.nativeGeocoder.reverseGeocode(this.becomeVendorDetails.latitude, this.becomeVendorDetails.longitude)
  L97:      .then((result: NativeGeocoderReverseResult) => {
  L98:          let addressLocal: any = JSON.stringify(result[0]);

        Argument of type '(result: NativeGeocoderReverseResult) => void' is not assignable to parameter of type 
[00:34:40]  typescript: src/pages/postjob/postjob.ts, line: 176 
        '(value: NativeGeocoderReverseResult[]) => void | PromiseLike<void>'. Types of parameters 'result' and 
        'value' are incompatible. Type 'NativeGeocoderReverseResult[]' is not assignable to type 
        'NativeGeocoderReverseResult'. 

 L175:  this.nativeGeocoder.reverseGeocode(this.bookingdetail.latitude, this.bookingdetail.longitude)
 L176:      .then((result: NativeGeocoderReverseResult) => {
 L177:          let addressLocal: any = JSON.stringify(result[0]);

        Argument of type '(result: NativeGeocoderReverseResult) => void' is not assignable to parameter of type 
        '(value: NativeGeocoderReverseResult[]) => void | PromiseLike<void>'. Types of parameters 'result' and 
[00:34:40]  typescript: src/pages/vendoreditprofile/vendoreditprofile.ts, line: 356 
        'value' are incompatible. Type 'NativeGeocoderReverseResult[]' is not assignable to type 
        'NativeGeocoderReverseResult'. 

 L355:  this.nativeGeocoder.reverseGeocode(this.profileDetail.latitude, this.profileDetail.longitude)
 L356:      .then((result: NativeGeocoderReverseResult) => {
 L357:          let addressLocal: any = JSON.stringify(result[0]);

In source code, becomevendor.ts

displayAddress() {
    this.nativeGeocoder.reverseGeocode(this.becomeVendorDetails.latitude, this.becomeVendorDetails.longitude)
        .then((result: NativeGeocoderReverseResult) => {
            let addressLocal: any = JSON.stringify(result[0]);
            let addressLoc = JSON.parse(addressLocal);
            let addressData = addressLoc.thoroughfare + ',' + addressLoc.locality + ',' + addressLoc.postalCode;
            this.becomeVendorForm.controls['address'].setValue(addressData);
            this.autocomplete.query = addressData;
        })
        .catch((error: any) => console.log(error));
}
close() {
    this.viewCtrl.dismiss();
}

Also this save function is available in other 2 files.

It looks like it is because nativeGeocoder.reverseGeocode returns a list of NativeGeocoderReverseResult

Change result from:

    .then((result: NativeGeocoderReverseResult) => {

to

    .then((result: NativeGeocoderReverseResult[]) => {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM