opik icon indicating copy to clipboard operation
opik copied to clipboard

Types in Client-BcByCGQn.d.ts Not Exported, Causing Usage Issues

Open serkon opened this issue 8 months ago • 2 comments

Hello Opik team,

Thank you for your work on this excellent library and for addressing part of the type export issue in #2034, where DatasetPublic was exported. However, I'm still encountering issues because other types defined in Client-BcByCGQn.d.ts (e.g., DatasetItemPublic, Span, Trace, OpikConfig, etc.) are not explicitly exported, preventing their use in my TypeScript project.

For example, in the following code:

import { ref } from 'vue';
const datasetItems = ref<DatasetItemPublic[]>([]);

I receive the following TypeScript compiler error:
TS2694: Namespace 'OpikApi' has no exported member 'DatasetItemPublic'.

The root cause is that, while DatasetPublic is now exported (thanks to the fix in #2034), other types in Client-BcByCGQn.d.ts are still not marked with the export keyword, restricting developers from referencing them.

Suggested Solution

To fully resolve this issue and improve TypeScript usability, I recommend explicitly exporting all relevant types in the Client-BcByCGQn.d.ts file, similar to what was done for DatasetPublic. This is a modular and standard practice in TypeScript libraries. For example:

export interface DatasetItemPublic {
  id?: string;
  traceId?: string;
  spanId?: string;
  source: DatasetItemPublicSource;
  data: JsonNode;
  experimentItems?: ExperimentItemPublic[];
  createdAt?: Date;
  lastUpdatedAt?: Date;
  createdBy?: string;
  lastUpdatedBy?: string;
}

export type DatasetItemPublicSource = "manual" | "trace" | "span" | "sdk";
export declare const DatasetItemPublicSource: {
  readonly Manual: "manual";
  readonly Trace: "trace";
  readonly Span: "span";
  readonly Sdk: "sdk";
};

export interface OpikConfig {
  apiKey: string;
  apiUrl?: string;
  projectName: string;
  workspaceName: string;
}

export interface Span {
  // ... relevant properties
}

export interface Trace {
  // ... relevant properties
}

// ... other types

This would allow users to import all necessary types as needed:

import { DatasetItemPublic, OpikConfig, Span, Trace } from '@opik/sdk';
const datasetItems: DatasetItemPublic[] = [];

This approach is:

  • Modular: Users can import only the types they need.
  • Standard: Aligns with common TypeScript library practices.
  • Safe: Avoids polluting the global namespace, ensuring compatibility across projects (e.g., Nuxt, React, Node.js).

Additional Information

  • Library Version: ^1.7.18
  • TypeScript Version: ^5.8.3
  • Project Environment: Nuxt 3, Vue 3
  • Example Code:
    import { ref } from 'vue';
    const datasetItems = ref<DatasetItemPublic[]>([]); // Error: DatasetItemPublic not exported
    
  • Related Issue: #2034

Conclusion

Exporting all relevant types in Client-BcByCGQn.d.ts, as was done for DatasetPublic, will make the library significantly more accessible and user-friendly for TypeScript developers. Thank you for addressing the initial issue in #2034, and I hope this can be extended to the remaining types. Please let me know if you need further details or clarification.

Thank you,
[Your Name or GitHub Username]

serkon avatar May 10 '25 10:05 serkon

Hey @serkon , sorry the late answer, we will take a look at it soon and get back to you

aadereiko avatar May 22 '25 08:05 aadereiko

@aadereiko I’ve decided to use the REST API SDK (https://www.comet.com/docs/opik/reference/rest-api/overview) in my project, so I no longer need these kinds of changes. However, someone else might still use a TypeScript SDK somewhere.

Thanks for answer

serkon avatar May 22 '25 08:05 serkon