Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.
This repository was archived by the owner on May 23, 2023. It is now read-only.

Why not use interfaces instead of classes? #128

@chlab

Description

@chlab

I am working on an implementation of a tracer that handles our organizations specific needs but ideally would use the interfaces defined by opentracing. Maybe I am missing something but I don't see how that would work the way the types are defined now, with classes instead of interfaces.

E.g. if I define my own Tracer class that expects certain properties on the SpanContext, TypeScript will tell me that these properties don't exist.

import { Tracer as OpenTracer, SpanContext } from 'opentracing';

class Tracer extends OpenTracer {
  startSpan(operationName: string, options: ISpanOptions = {}) {
    // ...
    let parent: SpanContext;
    // ...
    span.context.parentId = parent.spanId;
    // -> Property 'parentId' does not exist on type '() => SpanContext'
  }
}

If the opentracing types were interfaces, custom implementations could implement them and this wouldn't be a problem.

A consumer using my tracing implementation could not expect a span returned by my tracer's startSpan() to be of type opentracing Span.

Could you provide a few pointers on how you propose to create a custom tracer implementation that still uses the opentracing types?

Thanks 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions