[APM] Remove open-ended index signatures from interfaces (#34146)

This commit is contained in:
Søren Louv-Jansen 2019-04-01 10:01:21 +02:00 committed by GitHub
parent 6d0b7f4d91
commit 2d04e33288
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 16 additions and 23 deletions

View file

@ -5,13 +5,14 @@
*/
import { get } from 'lodash';
import { AllowUnknownProperties } from '../typings/common';
import { APMError } from '../typings/es_schemas/ui/APMError';
import { Span } from '../typings/es_schemas/ui/Span';
import { Transaction } from '../typings/es_schemas/ui/Transaction';
import * as fieldnames from './elasticsearch_fieldnames';
describe('Transaction', () => {
const transaction: Transaction = {
const transaction: AllowUnknownProperties<Transaction> = {
'@timestamp': new Date().toString(),
'@metadata': 'whatever',
observer: 'whatever',
@ -58,7 +59,7 @@ describe('Transaction', () => {
});
describe('Span', () => {
const span: Span = {
const span: AllowUnknownProperties<Span> = {
'@timestamp': new Date().toString(),
'@metadata': 'whatever',
observer: 'whatever',
@ -103,7 +104,7 @@ describe('Span', () => {
});
describe('Error', () => {
const errorDoc: APMError = {
const errorDoc: AllowUnknownProperties<APMError> = {
'@metadata': 'whatever',
observer: 'whatever',
agent: {
@ -156,7 +157,9 @@ describe('Error', () => {
matchSnapshot(errorDoc);
});
function matchSnapshot(obj: Span | Transaction | APMError) {
function matchSnapshot(
obj: AllowUnknownProperties<Span | Transaction | APMError>
) {
Object.entries(fieldnames).forEach(([key, longKey]) => {
const value = get(obj, longKey);
it(key, () => {

View file

@ -7,7 +7,7 @@
import { Location } from 'history';
import { Transaction } from 'x-pack/plugins/apm/typings/es_schemas/ui/Transaction';
export const transaction: Transaction = {
export const transaction = {
'@metadata': 'whatever',
observer: 'whatever',
agent: {
@ -77,7 +77,7 @@ export const transaction: Transaction = {
timestamp: {
us: 1545092070952472
}
};
} as Transaction;
export const location: Location = {
state: '',

View file

@ -7,3 +7,10 @@
export interface StringMap<T = unknown> {
[key: string]: T;
}
// Allow unknown properties in an object
export type AllowUnknownProperties<T> = T extends object
? { [P in keyof T]: AllowUnknownProperties<T[P]> } & {
[key: string]: unknown;
}
: T;

View file

@ -17,5 +17,4 @@ export interface APMBaseDoc {
labels?: {
[key: string]: string | number | boolean;
};
[key: string]: unknown;
}

View file

@ -27,13 +27,11 @@ interface Exception {
module?: string;
handled?: boolean;
stacktrace?: IStackframe[];
[key: string]: unknown;
}
interface Log {
message: string;
stacktrace?: IStackframe[];
[key: string]: unknown;
}
export interface ErrorRaw extends APMBaseDoc {
@ -50,9 +48,7 @@ export interface ErrorRaw extends APMBaseDoc {
// either exception or log are given
exception?: Exception[];
log?: Log;
[key: string]: unknown;
};
[key: string]: unknown;
// Shared by errors and transactions
container?: Container;

View file

@ -31,14 +31,11 @@ export interface SpanRaw extends APMBaseDoc {
url?: {
original?: string;
};
[key: string]: unknown;
};
db?: {
statement?: string;
type?: string;
[key: string]: unknown;
};
[key: string]: unknown;
};
transaction?: {
id: string;

View file

@ -31,7 +31,6 @@ export interface TransactionRaw extends APMBaseDoc {
agent?: {
[name: string]: number;
};
[key: string]: unknown;
};
name?: string;
result?: string;
@ -41,9 +40,7 @@ export interface TransactionRaw extends APMBaseDoc {
dropped?: number;
};
type: string;
[key: string]: unknown;
};
[key: string]: unknown;
// Shared by errors and transactions
container?: Container;

View file

@ -6,5 +6,4 @@
export interface Host {
hostname?: string;
[key: string]: unknown;
}

View file

@ -6,5 +6,4 @@
export interface Kubernetes {
pod: { uid: string; [key: string]: unknown };
[key: string]: unknown;
}

View file

@ -18,5 +18,4 @@ export interface Service {
name: string;
version?: string;
};
[key: string]: unknown;
}

View file

@ -19,7 +19,6 @@ interface IStackframeBase {
line: {
number: number;
};
[key: string]: unknown;
}
export interface IStackframeWithLineContext extends IStackframeBase {

View file

@ -6,5 +6,4 @@
export interface Url {
full: string;
[key: string]: unknown;
}

View file

@ -6,5 +6,4 @@
export interface User {
id: string;
[key: string]: unknown;
}