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(utils): Remove WINDOW from utils #6024

Merged
merged 4 commits into from Oct 24, 2022

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Oct 24, 2022

Fixes #6016

This issue is caused by the fact that Window ends up in the utils type definitions.

This PR:

  • Removes WINDOW from utils
  • In utils, it's usage is replaced with the following at the top of the appropriate files:
    // eslint-disable-next-line deprecation/deprecation. 
    const WINDOW = getGlobalObject<Window>();
  • Adds WINDOW to:
    • @sentry/browser where it is exported for use elsewhere
    • @sentry/tracing/browser - Can be removed once tracing is split into browser/node code
    • The Offline and ReportingObserver integrations since they don't have any dependencies other than utils
      • These could probably just use window since they're not used outside the browser
  • All downstream SDKs then import WINDOW from @sentry/browser or @sentry/react

@timfish timfish marked this pull request as ready for review October 24, 2022 11:22
*/
export const WINDOW = GLOBAL_OBJ as typeof GLOBAL_OBJ & Window;
// eslint-disable-next-line deprecation/deprecation
const WINDOW = getGlobalObject<Window>();
Copy link
Member

Choose a reason for hiding this comment

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

I think this still causes issues right? Since Window is at the top level.

Copy link
Collaborator Author

@timfish timfish Oct 24, 2022

Choose a reason for hiding this comment

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

I don't think the user reported issue has anything to do with top-level Window usage since the error directly references browser.d.ts:

node_modules/@sentry/utils/types/browser.d.ts:4:69 - error TS2304: Cannot find name 'Window'.

In master there is Window in browser.d.ts:

export declare const WINDOW: InternalGlobal & Window;
export declare function htmlTreeAsString(elem: unknown, keyAttrs?: string[]): string;
export declare function getLocationHref(): string;
export declare function getDomElement<E = any>(selector: string): E | null;

After this PR changes, browser.d.ts no longer has this:

export declare function htmlTreeAsString(elem: unknown, keyAttrs?: string[]): string;
export declare function getLocationHref(): string;
export declare function getDomElement<E = any>(selector: string): E | null;

And in the outputted JavaScript there are no generics or types so Window is gone too:

// eslint-disable-next-line deprecation/deprecation
const WINDOW = getGlobalObject();

Copy link
Member

Choose a reason for hiding this comment

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

Ah of course, it's not exported!

@AbhiPrasad AbhiPrasad merged commit c78fbf2 into getsentry:master Oct 24, 2022
@timfish timfish deleted the fix/window-in-utils-types branch November 29, 2022 09:37
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.

Sentry typescript type error introduced in 7.16.0
2 participants