Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions types/clerk.io/clerk.io-tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ConfigTypes, ResponseTypes } from "clerk.io";

if (window.Clerk) {
// @ts-expect-error
window.Clerk("click", 1);
Expand Down Expand Up @@ -31,4 +33,19 @@ if (window.Clerk) {
content.element; // $ExpectType HTMLElement
content.more(5);
});

// Test that newly exported ConfigTypes are accessible
const searchConfig: ConfigTypes["search/search"] = {
key: "test-key",
query: "test",
limit: 10,
};

// Test that newly exported ResponseTypes are accessible
const searchResponse: ResponseTypes["search/search"] = {
result: ["product1", "product2"],
count: 2,
facets: null,
status: "ok",
};
}
6 changes: 6 additions & 0 deletions types/clerk.io/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as Config from "./types/config";
import * as Helpers from "./types/helpers";
import * as Response from "./types/response";

// Re-export all types from submodules for direct access
export * from "./types/config";
export * from "./types/helpers";
export * from "./types/response";

export {};

export interface InitConfig {
Expand Down
6 changes: 3 additions & 3 deletions types/clerk.io/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"files": [
"index.d.ts",
"clerk.io-tests.ts",
"types/helpers.ts",
"types/config.ts",
"types/response.ts"
"types/helpers.d.ts",
"types/config.d.ts",
"types/response.d.ts"
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { IntRange } from "./helpers";

// Base types
interface BaseConfig {
export interface BaseConfig {
key: string;
/**
* @description Required for tracking. Visitor ID for the given visitor. If auto, an anonymous ID is generated
Expand All @@ -21,11 +21,11 @@ interface BaseConfig {
debug?: boolean;
}

type BaseLimitConfig = BaseConfig & {
export type BaseLimitConfig = BaseConfig & {
limit: number;
};

type BaseSearchConfig = BaseLimitConfig & {
export type BaseSearchConfig = BaseLimitConfig & {
/**
* @description Required for tracking - A list of one or more text labels, used to track the labels performance in Analytics
*/
Expand All @@ -45,7 +45,7 @@ type BaseSearchConfig = BaseLimitConfig & {
attributes?: string[];
};

type BaseFacetedConfig = BaseSearchConfig & {
export type BaseFacetedConfig = BaseSearchConfig & {
/**
* @description List of facets to be returned for the products in the result
* @see https://docs.clerk.io/docs/facets
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ClerkObject } from "clerk.io";
import type { ClerkObject } from "../index";

type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number]
export type Enumerate<N extends number, Acc extends number[] = []> = Acc["length"] extends N ? Acc[number]
: Enumerate<N, [...Acc, Acc["length"]]>;

export type IntRange<F extends number, T extends number> = Exclude<Enumerate<T>, Enumerate<F>>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import type { PickAttributes } from "./helpers";

// Base types
interface BaseResponse {
export interface BaseResponse {
result: (string | number)[];
status: string;
debug?: Record<string, unknown>;
}

type BaseProductResponse = BaseResponse & {
export type BaseProductResponse = BaseResponse & {
product_data?: PickAttributes<string[]>[];
};

type BaseCountedResponse = BaseProductResponse & {
export type BaseCountedResponse = BaseProductResponse & {
count: number;
facets: unknown | null;
};

// Common types
interface Category {
export interface Category {
children: number[];
description: string;
id: number;
Expand All @@ -28,7 +28,7 @@ interface Category {
url: string;
}

interface Page {
export interface Page {
author: string | null;
blog?: string;
created_at: number;
Expand Down
Loading