kibana/x-pack/plugins/observability/common/utils/as_mutable_array.ts
Dario Gieselaar 5bb9eecd26
[RAC] Populate Observability alerts table with data from alerts indices (#96692)
* Set up Observability rule APIs

* Populate alerts table with data from API

* Move field map types/utils to common

* Format reason/link in alert type

* Format reason/link in alert type

* Fix issues with tsconfigs

* Storybook cleanup for example alerts

* Use `MemoryRouter` in the stories and `useHistory` in the component to get the history
* Replace examples with ones from "real" data
* Use `() => {}` instead of `jest.fn()` in mock registry data

* Store/display evaluations, add active/recovered badge

* Some more story fixes

* Decode rule data with type from owning registry

* Use transaction type/environment in link to app

* Fix type issues

* Fix API tests

* Undo changes in task_runner.ts

* Remove Mutable<> wrappers for field map

* Remove logger.debug calls in alerting es client

* Add API test for recovery of alerts

* Revert changes to src/core/server/http/router

* Use type imports where possible

* Update limits

* Set limit to 100kb

Co-authored-by: Nathan L Smith <smith@nlsmith.com>
2021-04-15 18:25:50 +02:00

41 lines
1.1 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
// Sometimes we use `as const` to have a more specific type,
// because TypeScript by default will widen the value type of an
// array literal. Consider the following example:
//
// const filter = [
// { term: { 'agent.name': 'nodejs' } },
// { range: { '@timestamp': { gte: 'now-15m ' }}
// ];
// The result value type will be:
// const filter: ({
// term: {
// 'agent.name'?: string
// };
// range?: undefined
// } | {
// term?: undefined;
// range: {
// '@timestamp': {
// gte: string
// }
// }
// })[];
// This can sometimes leads to issues. In those cases, we can
// use `as const`. However, the Readonly<any> type is not compatible
// with Array<any>. This function returns a mutable version of a type.
export function asMutableArray<T extends Readonly<any>>(
arr: T
): T extends Readonly<[...infer U]> ? U : unknown[] {
return arr as any;
}