Skip to content

[7.x] [Alerting] Encourage type safe usage of Alerting (#86623)#86686

Merged
gmmorris merged 1 commit intoelastic:7.xfrom
gmmorris:backport/7.x/pr-86623
Dec 22, 2020
Merged

[7.x] [Alerting] Encourage type safe usage of Alerting (#86623)#86686
gmmorris merged 1 commit intoelastic:7.xfrom
gmmorris:backport/7.x/pr-86623

Conversation

@gmmorris
Copy link
Copy Markdown
Contributor

Backports the following commits to 7.x:

This PR encourages type safe usage of the Alerting framework by replacing the current default Params/State/InstanceState/InstanceContext types (which are `AlertTypeParams`/`AlertTypeState`/etc.) with `never`.
This means that code can continue to omit the specific types for these fields, as long as they aren't referenced.
Once an alert developer wishes to actually reference the parameters (or state/context), then they have to specify the type.

This PR also changed the typing of the `AlertTypeParams` and `AlertTypeState` from `Record<string, any>` to `Record<string, unknown>`, to ensure that where these catch-all types are used they will at least enforce `unknown` rather than `any`.
This change broke some usage in both @elastic/kibana-alerting-services  plugins, but also other plugins in the Stack/Solutions. I tried to fix these where I could, but some of these require new types and refactoring in other teams' code, which I decided is best done by the team who own and maintain that code - I've added explicit `TODO` comments in all of these places, describing the required fix.

This PR also introduced a Generics based typing for the `Alert` type so that the `params` field can be typed as something other than `AlertTypeParams`.
@gmmorris gmmorris added the backport This PR is a backport of another PR label Dec 21, 2020
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
stackAlerts 114.3KB 114.4KB +100.0B
triggersActionsUi 1.6MB 1.5MB -26.9KB
total -26.8KB

Distributable file count

id before after diff
default 47485 48248 +763

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
triggersActionsUi 162.6KB 162.6KB -24.0B
Unknown metric groups

async chunk count

id before after diff
triggersActionsUi 31 32 +1

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@gmmorris gmmorris merged commit c570612 into elastic:7.x Dec 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants