razshare / sveltekit-sse

Server Sent Events with SvelteKit
https://www.npmjs.com/package/sveltekit-sse
MIT License
267 stars 8 forks source link

Please export more types for use in a Typescript context #56

Closed kristianmandrup closed 4 weeks ago

kristianmandrup commented 1 month ago

I wanted to use the types such as:

export type SourceSelect<T = any> = (eventName: string) => import('svelte/store').Readable<string> & SourceSelected<T>;
export type Transformer<T = any> = (value: string) => T;
export type Jsonifier<T = any> = (or?: import("./types").JsonPredicate<any> | undefined) => import('svelte/store').Readable<null | T>;
export type SourceSelectedTransform<T = any> = (transformer: Transformer<T>) => any;
export type SourceSelected<T = any> = {
    /**
     * Transform the data into a custom shape.
     */
    transform: SourceSelectedTransform<T>;
    /**
     * Parse the data as json.
     */
    json: Jsonifier<T>;
};
export type Source<T = any> = {
    close: () => void;
    /**
     * Select an event from the stream.
     */
    select: SourceSelect;
};

But I don't seem able to import them. The index.d.ts with the types looks as follows.

export * from "./types.js";
import { source } from './source.js';
import { produce } from './produce.js';
export { source, produce };

Looks like it would require an

export * from './source'
export * from './produce'

to make all the most relevant types available for both client and server.

razshare commented 1 month ago

Hello @kristianmandrup , thanks for the issue!

Looks like it would require an

export * from './source'
export * from './produce'

That I won't do. A library should not expose internal types and confuse userland. It has to be a manual process, not just export *. I went through all the types and function/object signatures and identified all the types that are required for userland.

Please update to version 0.13.5 to get the latest changes.

There are some breaking changes because I found 2 types that haven't been updated for some time and needed a name change. See breaking changes in release notes.

Other than that, you should now have access to all the types you need.

Peek 2024-07-28 13-36


Let me know if this addresses your issue.

razshare commented 4 weeks ago

I'm closing this issue due to inactivity. Feel free to open a new one or follow up on this one if you need to.