Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript types for FirebaseApp require unsettable automaticDataCollectionEnabled #2189

Closed
zeroasterisk opened this issue Sep 24, 2019 · 2 comments · May be fixed by #2190
Closed

Typescript types for FirebaseApp require unsettable automaticDataCollectionEnabled #2189

zeroasterisk opened this issue Sep 24, 2019 · 2 comments · May be fixed by #2190

Comments

@zeroasterisk
Copy link

  • Operating System version: osx
  • Browser version:
  • Firebase SDK version: 6.6.1
  • Firebase Product: FirebaseApp (typescript)
├─┬ firebase@6.6.1
│ ├─┬ @firebase/app@0.4.16
│ │ ├── @firebase/app-types@0.4.3 deduped
$ tsc --version
Version 3.6.2

Problem:

I can use app.initializeApp(config) to create a FirebaseApp app.
But Typescript is never happy.

The 2 errors I get are:

Property 'automaticDataCollectionEnabled' is missing in type 'App' but required in type 'FirebaseApp'. TS2741
or
Argument of type 'FirebaseAppConfig' is not assignable to parameter of type 'string'. TS2345

Steps to reproduce: Without the AppConfig, name as string

import { FirebaseApp, FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';
import * as app from 'firebase/app';

const config: FirebaseOptions = {...};
const appName: string = 'Decryptilito';
const myApp: FirebaseApp = app.initializeApp(config, appName);

Results in error:

Property 'automaticDataCollectionEnabled' is missing in type 'App' but required in type 'FirebaseApp'. TS2741

Steps to reproduce: With the AppConfig

import { FirebaseApp, FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';
import * as app from 'firebase/app';

const config: FirebaseOptions = {...};
const appConf: FirebaseAppConfig = { name: 'Decryptilito', automaticDataCollectionEnabled: false };
const myApp: FirebaseApp = app.initializeApp(config, appConf);

Results in error:

Argument of type 'FirebaseAppConfig' is not assignable to parameter of type 'string'. TS2345

Possible solution

I suspect that maybe types and JS code have diverged a bit?

https://github.com/firebase/firebase-js-sdk/blob/master/packages/app-types/index.d.ts#L49

When I'm looking at the overloaded types def of initializeApp() I see both supported, but I can't us the config based one.

Also, I see that automaticDataCollectionEnabled is optional in the config, but required in the app itself.

@google-oss-bot
Copy link
Contributor

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

zeroasterisk added a commit to zeroasterisk/firebase-js-sdk that referenced this issue Sep 24, 2019

Unverified

The committer email address is not verified.
@Feiyang1
Copy link
Member

Feiyang1 commented Oct 1, 2019

Types from @firebase/app-types are not meant to be used directly. You should only use the types directly exposed by import * as firebase from firebase. For example:

import * as firebase from 'firebase/app';

const config = {...};
const appName: string = 'Decryptilito';
const myApp: firebase.app.App = firebase.initializeApp(config, appName);

@Feiyang1 Feiyang1 closed this as completed Oct 1, 2019
@firebase firebase locked and limited conversation to collaborators Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants