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: Change parameter name to give more useful TypeScript error on SDK version mismatch #584

Merged
merged 2 commits into from
Nov 9, 2022

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Nov 3, 2022

Closes #583

The error reported in the above issue would now read:

Argument of type '(if_you_get_a_typescript_error_ensure_sdks_use_version_v7_16_0: import("d:/dev/projects/glint/angular/node_modules/@sentry/browser/types/client").BrowserOptions) => void' is not assignable to parameter of type '(options: import("d:/dev/projects/glint/angular/node_modules/@sentry/electron/node_modules/@sentry/browser/types/client").BrowserOptions) => void'.
  Types of parameters 'if_you_get_a_typescript_error_ensure_sdks_use_version_v7_16_0' and 'options' are incompatible.
    Type 'import("d:/dev/projects/glint/angular/node_modules/@sentry/electron/node_modules/@sentry/browser/types/client").BrowserOptions' is not assignable to type 'import("d:/dev/projects/glint/angular/node_modules/@sentry/browser/types/client").BrowserOptions'.
      Types of property 'defaultIntegrations' are incompatible.
        Type 'false | import("d:/dev/projects/glint/angular/node_modules/@sentry/electron/node_modules/@sentry/types/types/integration").Integration[] | undefined' is not assignable to type 'false | import("d:/dev/projects/glint/angular/node_modules/@sentry/types/types/integration").Integration[] | undefined'.

@timfish timfish assigned timfish and unassigned timfish Nov 3, 2022
@timfish timfish marked this pull request as draft November 3, 2022 12:11
@timfish timfish self-assigned this Nov 3, 2022
@timfish timfish marked this pull request as ready for review November 3, 2022 12:23
Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Let's do it!

@lucas-zimerman
Copy link

In this case, wouldn't it also give a margin of error to the user where the user installs "@sentry/angular": "^7.16.0" instead of "@sentry/angular": "7.16.0"?

@timfish
Copy link
Collaborator Author

timfish commented Nov 6, 2022

In this case, wouldn't it also give a margin of error to the user where the user installs

Yes correct, this doesn't check the versions at all, it just means that if the types don't match, the error displayed by TypeScript is more helpful. We no doubt go through quite a few patch releases before the types become incompatible so this is not foolproof.

We could add version specific properties to some key types that cause the types to break immediately if versions don't match like:

interface ClientOptions {
  _sdk_version_v7_16_0?: bool
}

@AbhiPrasad
Copy link
Member

We could add version specific properties to some key types that cause the types to break immediately if versions don't match like

yeah but this could possibly be a breaking change. could we just update the injected type for if_you_get_a_typescript_error_ensure_sdks_use_version to only use major + minor version?

@timfish
Copy link
Collaborator Author

timfish commented Nov 9, 2022

yeah but this could possibly be a breaking change

This would only break the TypeScript builds of those using mismatched versions of SDKs and that is neither tested nor supported. If any customers have mismatched versions that are currently working, this is purely luck, even with only patch version differences.

could we just update the injected type for if_you_get_a_typescript_error_ensure_sdks_use_version to only use major + minor version

I don't think we can do anything from the top-level types since we need there to be a mismatch between the common types in @sentry/electron and whichever front-end SDK is being passed in (ie. @sentry/core).

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

I don't think we can do anything from the top-level types since we need there to be a mismatch between the common types in @sentry/electron and whichever front-end SDK is being passed in (ie. @sentry/core).

This is a good point. Given that I'd be fine with updating the types this way and merging this in.

Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

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

I think this is a good small improvement for this context!

@timfish timfish merged commit cd7ffcb into getsentry:master Nov 9, 2022
@timfish timfish deleted the fix/improve-typescript-error branch November 18, 2022 13:38
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.

Electron with Angular cannot init
4 participants