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

fix: return typing of global functions #1081

Merged
merged 1 commit into from
Mar 14, 2024
Merged

fix: return typing of global functions #1081

merged 1 commit into from
Mar 14, 2024

Conversation

daibhin
Copy link
Contributor

@daibhin daibhin commented Mar 14, 2024

Changes

Seeing these errors locally

src/extensions/replay/sessionrecording.ts:644:9 - error TS2322: Type 'Timeout' is not assignable to type 'number'.

644         this._fullSnapshotTimer = setInterval(() => {
            ~~~~~~~~~~~~~~~~~~~~~~~

src/request-queue.ts:50:9 - error TS2322: Type 'Timeout' is not assignable to type 'number'.

50         this.flushTimeout = setTimeout(() => {
           ~~~~~~~~~~~~~~~~~

src/request.ts:159:13 - error TS2322: Type 'Timeout' is not assignable to type 'number'.

159             timeout: setTimeout(() => controller.abort(), options.timeout),
                ~~~~~~~


Found 3 errors.

Don't know why this only happens in my environment but TS suggests the return type should be NodeJS.Timeout. Depending on the environment posthog-js is running in we can support the global functions return type.

More context: https://stackoverflow.com/questions/45802988/typescript-use-correct-version-of-settimeout-node-vs-window

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Copy link

Size Change: 0 B

Total Size: 853 kB

ℹ️ View Unchanged
Filename Size
dist/array.full.js 183 kB
dist/array.js 124 kB
dist/es.js 124 kB
dist/exception-autocapture.js 12.1 kB
dist/module.js 124 kB
dist/recorder-v2.js 106 kB
dist/recorder.js 58.7 kB
dist/surveys-module-previews.js 62 kB
dist/surveys.js 58.3 kB

compressed-size-action

@daibhin daibhin merged commit f6442ef into main Mar 14, 2024
14 checks passed
@daibhin daibhin deleted the dn-fix/typing branch March 14, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants