Skip to content

Commit 0d1161b

Browse files
committed
chore(async-stack): manually define public type for StackItem
1 parent d9d7509 commit 0d1161b

4 files changed

Lines changed: 39 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@svelte-put/async-stack': patch
3+
---
4+
5+
provide explicit d.ts for `StackItem` for greater control
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import type { Component } from 'svelte';
3+
4+
import type { StackItemInstanceConfig, StackItemState } from './types.package';
5+
import type { ComponentResolved } from './types.public';
6+
7+
export class StackItem<
8+
UserComponent extends Component<any>,
9+
Resolved = ComponentResolved<UserComponent>,
10+
> {
11+
/** @default 'idle' */
12+
state: StackItemState;
13+
config: Required<StackItemInstanceConfig<string, UserComponent>>;
14+
/**
15+
* a promise that resolves when the item is resolved,
16+
* by timing out or via the .resolve method
17+
*/
18+
resolution: Promise<Resolved | undefined>;
19+
20+
constructor(config: StackItemInstanceConfig<string, UserComponent>);
21+
22+
/** resume the stack item, if it has been paused */
23+
resume: () => void;
24+
/** pause the stack item, if it has a timeout */
25+
pause: () => void;
26+
/**
27+
* resolve the stack item, optionally with a resolved value
28+
* resolve means popping the item from the stack, and
29+
* unmounting its component
30+
*/
31+
resolve: (resolved?: Resolved) => Promise<Resolved | undefined>;
32+
}

packages/async-stack/src/stack-item.svelte.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ export class StackItem {
1818
resolve: () => {},
1919
};
2020

21-
/**
22-
* a promise that resolves when the item is popped or resolved via the .resolve method
23-
* @type {Promise<Resolved | undefined>}
24-
*/
21+
/** @type {Promise<Resolved | undefined>} */
2522
resolution;
2623

2724
/**

packages/async-stack/src/types.public.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { StackItem } from './stack-item.svelte.js';
55

66
export interface StackItemProps<Resolved = undefined> {
77
/** the stack item instance injected by the stack */
8-
item: Omit<StackItem<Component<StackItemProps<Resolved>>, Resolved>, '#internals'>;
8+
item: StackItem<Component<StackItemProps<Resolved>>, Resolved>;
99
}
1010

1111
export type ComponentResolved<UserComponent extends Component<any>> =

0 commit comments

Comments
 (0)