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

[main][doc] add document for how to fix type error in extensions #2395

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ This version comes with the bare minimum amount of features and functionalities
| [React](https://github.com/microsoft/applicationinsights-react-js) | [![npm version](https://badge.fury.io/js/%40microsoft%2Fapplicationinsights-react-js.svg)](https://www.npmjs.com/package/@microsoft/applicationinsights-react-js)
| [React Native](https://github.com/microsoft/applicationinsights-react-native) | [![npm version](https://badge.fury.io/js/%40microsoft%2Fapplicationinsights-react-native.svg)](https://www.npmjs.com/package/@microsoft/applicationinsights-react-native)

Click here for a [Type Error Fixed Guideline](https://microsoft.github.io/ApplicationInsights-JS/ExtensionErrorSteps)

## Build a new extension for the SDK

The SDK supports the ability to include multiple extensions at runtime. In order to create a new extension, please implement the following interface:
Expand Down
38 changes: 38 additions & 0 deletions docs/ExtensionErrorSteps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Investigating and Solving Plugin-Type Errors in Extensions

This guide addresses plugin-type errors encountered when using the `applicationinsights-web` package alongside other extensions, such as `@microsoft/applicationinsights-react-js`, `@microsoft/applicationinsights-react-native`, and `@microsoft/applicationinsights-angularplugin-js`.

## Overview

A common error message associated with these issues might look like this:

```plaintext
Type 'ReactPlugin' is not assignable to type 'ITelemetryPlugin'.
```

Plugin-type errors often arise due to version mismatches between applicationinsights-web and its extensions.

## Reason

When a new version of applicationinsights-web (which includes applicationinsights-core as a dependency) is released, package management tools may automatically update applicationinsights-core to the new version. However, if the extensions (e.g., React, Angular) have not been updated, their dependencies on applicationinsights-core may not match, leading to type errors.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be good to call out here that this is a TypeScript issue only as we work really hard to ensure that while the "types" (might) appear different to different versions of TypeScript at runtime the code should still interoperate as long as the "core" version is later than any sub-component as we support backward compatibility but not forward compatibility.

Which means we support older components working with "newer" dependencies (ie the newer dependency is backward compatible for older components) but not newer components working with "older" dependencies.

A good example of this is that we may from time to time "add" new public helper functions to core components that some "newer" extensions might use / need. As such that "newer" function is only available in the "newer" version of the core component and not in the older previous published components. (ie. we don't know now (or back then) what functions we "might" need in a future release -- why I call it forward compatibility)


## Steps to Investigate and Solve Plugin-Type Errors

### 1. Verify Package Versions

- **Check Dependencies**: Ensure that you have compatible versions of applicationinsights-common, applicationinsights-core, and any other related libraries. Look for discrepancies in your yarn.lock or package-lock.json or node_modules folder.
![alt text](./media/pluginType.png)

### 2. Perform a Complete Update
The easiest way to ensure all dependencies are updated is to delete the node_modules folder and reinstall the packages:
```
rm -rf node_modules
npm install
```
### 3. Examples to follow
Here is a discussion that provide deeper insights into resolving these issues:
https://github.com/microsoft/applicationinsights-react-js/issues/95
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there is a new TypeScript flag (which most people wont use) -

  • skipLibCheck
  • noCheck
    I thought I read recently (somewhere) that there was a new config but I can't find it currently

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Will check that potential walk around before merge this pr.





Binary file added docs/media/pluginType.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading