flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
43 stars 5 forks source link

TS Import Issue #108

Closed erik-slack closed 4 years ago

erik-slack commented 4 years ago

The docs say to use import flamelink from 'flamelink';

but because of the default rule

"allowSyntheticDefaultImports": false

I get this from my tslint:

image

So changing it to

import * as flamelink from 'flamelink/app';

was what I figured would fix it, but then I get this at runtime:

TypeError: flamelink_app__WEBPACK_IMPORTED_MODULE_7__ is not a function image

I can bypass this issue by adding "allowSyntheticDefaultImports": true in my tsconfig.json to compilerOptions. But that just seems wrong.

Am I doing this wrong?

jperasmus commented 4 years ago

Hi Erik, no, you are doing it right :)

Flamelink's export requires either synthetic default imports or the esModuleInterop flag to be enabled. This is because of the design decision we made to have the main export the Flamelink app factory function, ie. flamelink({ ...config }). I'm not sure at this stage if it is the best. We've considered changing it to be similar to how Firebase's SDK works, which will then export an object and you have to call the initializeApp method on it, ie. firebase.initializeApp({ ...config }).

Does the allowSyntheticDefaultImports break anything for you?

erik-slack commented 4 years ago

No it doesn't, it just throws a linter error. I'll set it to allowed then. Thanks, it helps knowing you've made it that way on purpose.

jperasmus commented 4 years ago

Do you perhaps have more info on what type of bugs that linting rule would catch? I'm not aware of any specific problems with using synthetic default imports.

erik-slack commented 4 years ago

After reading up more about it I think you're good. Sorry for the snipe hunt!

My source: https://github.com/Microsoft/TypeScript/issues/10895