Typescript Error Property 'text' does not exist on type 'Object'

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Typescript Error Property 'text' does not exist on type 'Object'



I am editing in the database and there was a typescript error 2339
Here is the code


import HttpClient from '@angular/common/http';
import Injectable from '@angular/core';
import Storage from '@ionic/storage';
import Platform from 'ionic-angular';
import SQLite, SQLiteObject from '@ionic-native/sqlite';
import SQLitePorter from '@ionic-native/sqlite-porter'
import BehaviorSubject from 'rxjs/Rx';
import 'rxjs/add/operator/map';

/*
Generated class for the DatabaseProvider provider.

See https://angular.io/guide/dependency-injection for more info on
providers
and Angular DI.
*/
@Injectable()
export class DatabaseProvider
database: SQLiteObject;
private dbReady: BehaviorSubject<boolean>;

constructor(public http: HttpClient, private sqlitePorter: SQLitePorter, private storage: Storage, private sqlite: SQLite, private platform: Platform)

this.dbReady = new BehaviorSubject(false);
this.platform.ready().then(() =>
this.sqlite.create(
name: 'assessment.db',
location: 'default'
)
.then((db:SQLiteObject) =>
this.database = db;
this.storage.get('database_filled').then(val =>
if(val)
this.dbReady.next(true);

else
this.fillDatabase();

)
);
);


fillDatabase()
this.http.get('assets/test.sql')
.map (res => res.text())
.subscribe(sql =>
this.sqlitePorter.importSqlToDb(this.database, sql)
.then(data =>
this.dbReady.next(true);
this.storage.set('database_filled', true);
)
);


getDatabaseState()
return this.dbReady.asObservable();





.map (res => res.text()) this part returns an error. I have tried to alter this and made it .map ((res: Response) => res.text()) then another error would prompt and that is in the line this.sqlitePorter.importSqlToDb(this.database, sql) the error is " Argument of type Promise is not assignable to parameter of type .




1 Answer
1



With HttpClient, you no longer need to map the result of a Http call as it returns the result by default rather than the response object. If the result of your http call is already a string then just remove the .map line. i.e.


HttpClient


Http


.map


fillDatabase()
this.http.get<string>('assets/test.sql')
.subscribe(sql =>
this.sqlitePorter.importSqlToDb(this.database, sql)
.then(data =>
this.dbReady.next(true);
this.storage.set('database_filled', true);
)
);





i deleted it the next error is the promise string in this line this.sqlitePorter.importSqlToDb(this.database, sql) it highlighted sql.
– Rona Cecilia Abayata
Aug 8 at 2:43





@RonaCeciliaAbayata, I updated my answer. Your get call should specify the return type of the object, which in this case is string, otherwise it gets defaulted to be object.
– Simon K
Aug 8 at 2:53


get


string


object





thank you. the first error was solved. now my problem is with this line, this.sqlitePorter.importSqlToDb(this.database, sql) it returns this error (Typescript Error Argument of type 'Object' is not assignable to parameter of type 'string'.)
– Rona Cecilia Abayata
Aug 8 at 2:59





Did you update your call to be this.http.get<string>? If this didn't work, which it should have, update your subscribe line to be .subscribe((sql: string) => {
– Simon K
Aug 8 at 3:08


this.http.get<string>


.subscribe((sql: string) => {





thank you so much. it did not return an error anymore.
– Rona Cecilia Abayata
Aug 8 at 3:13






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard