Skip to content

Improve TypeScript types for SDK response objects #361

Description

@Antardas

Summary

The TypeScript response types in the crw-sdk package are very generic, making it difficult to use the SDK with proper type safety and IntelliSense.

Currently the SDK exposes:

export type ScrapeResult = Json;
export type CrawlResult = Json[];
export type SearchResult = Json | Json[];
export type ParseResult = Json;

/** Native `/v1/extract` returns one result object per URL, in request order. */
export type ExtractResult = ExtractUrlResult[];
// ...

Problem

Since ScrapeResult is just Json, TypeScript cannot infer any of the response properties.

For example, fields such as:

  • markdown
  • metadata
  • images
  • links
  • actions
  • etc.

are not typed, so users lose autocomplete and compile-time type checking.

Expected behavior

It would be helpful if the SDK exported detailed interfaces for the API responses instead of Json.

For example:

interface ScrapeResult {
  markdown?: string;
  html?: string;
  metadata?: ScrapeMetadata;
  images?: ScrapeImage[];
  actions?: ScrapeAction[];
  // ...
}

This would provide much better IntelliSense and make the SDK easier to use in TypeScript projects.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions