# Import of @types/q not working in my code

**URL:** <https://forum.ionicframework.com/t/import-of-types-q-not-working-in-my-code/102489>\
**Category:** ionic-v3\
**Created:** [August 18, 2017, 5:03pm UTC](https://forum.ionicframework.com/t/import-of-types-q-not-working-in-my-code/102489 "2017-08-18T17:03:25Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 18, 2017, 10:20pm UTC](https://forum.ionicframework.com/t/import-of-types-q-not-working-in-my-code/102489/7 "2017-08-18T22:20:51Z")

</div>

If you aren’t doing fancy SQL queries and joins, which is the case for probably 95% of mobile apps, you might want to look into using [ionic-storage](https://ionicframework.com/docs/storage/), as the API is much simpler and, unlike direct interaction with SQLite, it works just fine in browser environments as well.

That being said, [here](https://forum.ionicframework.com/t/ionic-app-loading-sequence/100109/11?u=rapropos) are some rules I have made for myself when dealing with asynchronous code. In this case, `connectToDb()` falls into the third category, so make the first word of it be `return` (and I would get rid of `async`).

I also don’t like “gatekeeper” variables like `isConnectedToDB`. Everything that’s accessible should always be in a usable state. [This thread](https://forum.ionicframework.com/t/how-to-get-the-localstorage-value-out-of-promise-scope/57296) describes an idiom that you might adapt, where `db` is not exposed as a raw property, but rather as a `Promise` itself.

In the long run, however, I think the safest, cleanest, and clearest way to do any of this is to never expose any details of storage implementation outside of service providers, so this whole `connectToDb()` shouldn’t be callable from outside, if it even exists once we’re done refactoring things. When it comes to the notion of conditionally setting root pages based on external events such as user authentication state, I use [this pattern](https://forum.ionicframework.com/t/how-to-handle-case-where-user-is-still-authenticated-they-can-skip-login/92563/2?u=rapropos), in which your app component doesn’t need to know or care how user authentication happens, just when it has.

---

_[View the full topic](https://forum.ionicframework.com/t/import-of-types-q-not-working-in-my-code/102489)._
