-
Notifications
You must be signed in to change notification settings - Fork 129
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
feat: type safe posthog extensions #1407
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Size Change: +4.42 kB (+0.36%) Total Size: 1.22 MB
ℹ️ View Unchanged
|
src/utils/globals.ts
Outdated
interface PosthogExtensions { | ||
parseErrorAsProperties?: ([event, source, lineno, colno, error]: ErrorEventArgs) => ErrorProperties | ||
errorWrappingFunctions?: { | ||
wrapOnError: (captureFn: (props: Properties) => void) => () => void | ||
wrapUnhandledRejection: (captureFn: (props: Properties) => void) => () => void | ||
} | ||
rrweb?: { record: any; version: string; rrwebVersion: string } | ||
rrwebPlugins?: { getRecordConsolePlugin: any; getRecordNetworkPlugin?: any } | ||
canActivateRepeatedly?: (survey: any) => boolean | ||
webVitalsCallbacks?: { | ||
onLCP: (metric: any) => void | ||
onCLS: (metric: any) => void | ||
onFCP: (metric: any) => void | ||
onINP: (metric: any) => void | ||
} | ||
tracingHeadersPatchFns?: { | ||
_patchFetch: (sessionManager: SessionIdManager) => () => void | ||
_patchXHR: (sessionManager: any) => () => void | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's the secret sauce... we've added a bunch of stuff directly to window and you can't really see what without reading a bunch of files, and you don't get any typesafety at all since it's all (window as any)
we'd have to be careful here not to bring in the lazy bundles and inflate the bundle unnecessarily
but this is at least a step better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets go! Just a small suggestion
src/utils/globals.ts
Outdated
import { SessionIdManager } from '../sessionid' | ||
import { ErrorEventArgs, ErrorProperties, Properties } from '../types' | ||
import { PostHog } from '../posthog-core' | ||
import { SurveyManager } from '../extensions/surveys' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Errrr surely this isn't what you want...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I am surprised the bundle didn't grow much it still seems like we should never be importing from extensions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah... the fun of offsite brain tiredness. Should have a linter maybe to save in future... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nicer if we had interfaces instead of these any
s but alreayd a lot changing in here so 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we could do import type
and that would give you what you want but thats also at risk of getting changed and importing the actual data too...
We keep adding more and more things directly to window
We get no type help from TS
And we're not being super unique with naming so could easily clash with someone else
Let's be a little more explicit about where and what we add to the window