diff options
Diffstat (limited to 'ui/src/controller/consumer_port_types.ts')
-rw-r--r-- | ui/src/controller/consumer_port_types.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/ui/src/controller/consumer_port_types.ts b/ui/src/controller/consumer_port_types.ts index cb054e1ba..8b3cd453c 100644 --- a/ui/src/controller/consumer_port_types.ts +++ b/ui/src/controller/consumer_port_types.ts @@ -18,6 +18,17 @@ export interface Typed { type: string; } +// A type guard that can be used in order to be able to access the property of +// an object in a checked manner. +export function hasProperty<T extends object, P extends string>( + obj: T, prop: P): obj is T&{[prop in P]: unknown} { + return obj.hasOwnProperty(prop); +} + +export function isTyped(obj: object): obj is Typed { + return obj.hasOwnProperty('type'); +} + export interface ReadBuffersResponse extends Typed, perfetto.protos.IReadBuffersResponse {} export interface EnableTracingResponse extends @@ -48,11 +59,6 @@ export function isGetTraceStatsResponse(obj: Typed): return obj.type === 'GetTraceStatsResponse'; } -export function isGetCategoriesResponse(obj: Typed): - obj is GetCategoriesResponse { - return obj.type === 'GetCategoriesResponse'; -} - export function isFreeBuffersResponse(obj: Typed): obj is FreeBuffersResponse { return obj.type === 'FreeBuffersResponse'; } |