firebase / firebase/firebase-js-sdk
Can't pass combination of expected and custom event names to analytics' logEvents()
- 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
Assessment
This issue has not been assessed yet.