analytics.user function should be listed as optionally undefined in typescript definitions
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- api
Research direction
Start by locating the TypeScript definition for AnalyticsSnippet and its user member in the analytics-next package. Check the existing type tests or validation commands, if present; done means the definition reflects that user may be absent and the shown optional call type-checks without permitting the unsafe call.
Written by the indexing model from the issue text.
Description
We are running into an issue for users that have ad blocking or cross-site tracking disabled.
Our code:
import type { AnalyticsSnippet } from '@segment/analytics-next';
const getAnalytics = (): AnalyticsSnippet | undefined => typeof window !== 'undefined' ? window.analytics : undefined;
getAnalytics()?.user()
Throws the error:
VM70:1 Uncaught TypeError: analytics.user is not a function
at <anonymous>:1:11
My expectation is that the typescript definition lists the user function as optionally undefined so that typescript enforces that we call the code as:
getAnalytics()?.user?.()
This would prevent us from running into runtime errors for users with ad blockers or cross site trackers disabled.
We are using @segment/analytics-next@1.70.0 & typescript@5.5.2
- Dominant language
- TypeScript
- Stars
- 477
- Forks
- 160
- Avg merge
- 6h 19m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from segmentio/analytics-next
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
segmentio/analytics-next#1324 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
segmentio/analytics-next#1366 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
segmentio/analytics-next#1338 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
segmentio/analytics-next#1337 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
segmentio/analytics-next#1332 ·
All issues in segmentio/analytics-next
Similar issues
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 76/100
-
code-quality refactoring
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
vercel/react-tweet#225 ·