firebase / firebase/firebase-js-sdk

Can't pass combination of expected and custom event names to analytics' logEvents()

Open
#6,432 3 comments 0 reactions 0 assignees View on GitHub
api: analytics bug v9
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

* Operating System version: macOS 10.15.7
* Browser version: Brave latest
* Firebase SDK version: 9.6.10
* Firebase Product: analytics

Setup code:
```ts
import { initializeApp } from "firebase/app"
import { getAnalytics, logEvent } from "firebase/analytics"

const firebaseApp = initializeApp(firebaseConfig)
const analytics = getAnalytics(firebaseApp)
```

Working:
```ts
type CustomEventNamesOnly = "some_custom_event" | "some_other_custom_event"
logEvent(analytics, eventName, eventParams)
```

Also working:
```ts
type ExpectedEventNamesOnly = "select_item" | "set_checkout_option"
logEvent(analytics, eventName as ExpectedEventNamesOnly, eventParams)
```

Not working:
```ts
type CustomAndStandardEventNames = "some_custom_event" | "select_item"
logEvent(analytics, eventName, eventParams)
```

In reality I'm using `logEvent` inside of a function that I'm calling from multiple places in my app, and I want to pass something like `CustomAndStandardEventNames` to `logEvent` as the type for `eventName`.

It currently returns an error because of [this type](https://github.com/JGJP/firebase-js-sdk/blob/39f4635ebc07316661324145f1b8c27f9bd7aedb/packages/analytics/src/api.ts#L738) narrowing to `never` when the event name extends `EventNameString` but I don't see a good reason for this.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.