Skip to content

Commit e90d10e

Browse files
committed
fix(type): fix type issue
1 parent 42c6b04 commit e90d10e

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"react-dom": "^18.2.0",
7070
"rimraf": "^4.4.0",
7171
"rollup": "^4.52.3",
72-
"travels": "^0.5.1",
72+
"travels": "^0.5.2",
7373
"ts-node": "^10.9.2",
7474
"tslib": "^2.8.1",
7575
"typedoc": "^0.26.11",
@@ -87,6 +87,6 @@
8787
"@types/react": "^17.0 || ^18.0 || ^19.0",
8888
"mutative": "^1.3.0",
8989
"react": "^17.0 || ^18.0 || ^19.0",
90-
"travels": "^0.5.1"
90+
"travels": "^0.5.2"
9191
}
9292
}

src/index.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ import type {
66
TravelsControls,
77
Value,
88
Updater,
9-
InitialValue,
9+
PatchesOption,
1010
} from 'travels';
1111
import { Travels } from 'travels';
1212

1313
export type { TravelPatches };
1414

15-
type Result<S, F extends boolean, A extends boolean> = [
15+
type Result<
16+
S,
17+
F extends boolean,
18+
A extends boolean,
19+
P extends PatchesOption = {},
20+
> = [
1621
Value<S, F>,
1722
(updater: Updater<S>) => void,
18-
A extends false ? ManualTravelsControls<S, F> : TravelsControls<S, F>,
23+
A extends false ? ManualTravelsControls<S, F, P> : TravelsControls<S, F, P>,
1924
];
2025

2126
/**
@@ -24,21 +29,34 @@ type Result<S, F extends boolean, A extends boolean> = [
2429
export function useTravel<S, F extends boolean>(
2530
initialState: S
2631
): [Value<S, F>, (updater: Updater<S>) => void, TravelsControls<S, F>];
27-
export function useTravel<S, F extends boolean>(
32+
export function useTravel<
33+
S,
34+
F extends boolean,
35+
A extends boolean,
36+
P extends PatchesOption = {},
37+
>(
2838
initialState: S,
29-
options: Omit<TravelsOptions<F, true>, 'autoArchive'> & { autoArchive?: true }
30-
): [Value<S, F>, (updater: Updater<S>) => void, TravelsControls<S, F>];
31-
export function useTravel<S, F extends boolean>(
39+
options: Omit<TravelsOptions<F, true, P>, 'autoArchive'> & {
40+
autoArchive?: true;
41+
}
42+
): [Value<S, F>, (updater: Updater<S>) => void, TravelsControls<S, F, P>];
43+
export function useTravel<
44+
S,
45+
F extends boolean,
46+
A extends boolean,
47+
P extends PatchesOption = {},
48+
>(
3249
initialState: S,
33-
options: Omit<TravelsOptions<F, false>, 'autoArchive'> & {
50+
options: Omit<TravelsOptions<F, false, P>, 'autoArchive'> & {
3451
autoArchive: false;
3552
}
36-
): [Value<S, F>, (updater: Updater<S>) => void, ManualTravelsControls<S, F>];
37-
export function useTravel<S, F extends boolean, A extends boolean>(
38-
initialState: S,
39-
_options: TravelsOptions<F, A> = {}
40-
): Result<S, F, A> {
41-
// Validate options in development mode (using __DEV__ for consistency with existing codebase)
53+
): [Value<S, F>, (updater: Updater<S>) => void, ManualTravelsControls<S, F, P>];
54+
export function useTravel<
55+
S,
56+
F extends boolean,
57+
A extends boolean,
58+
P extends PatchesOption = {},
59+
>(initialState: S, _options: TravelsOptions<F, A, P> = {}): Result<S, F, A, P> {
4260
if (__DEV__) {
4361
const { maxHistory = 10, initialPosition = 0, initialPatches } = _options;
4462

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4387,10 +4387,10 @@ tr46@^6.0.0:
43874387
dependencies:
43884388
punycode "^2.3.1"
43894389

4390-
travels@^0.5.1:
4391-
version "0.5.1"
4392-
resolved "https://registry.yarnpkg.com/travels/-/travels-0.5.1.tgz#54494ab4025ac3bb0b2fc27eefae35a7e42402f8"
4393-
integrity sha512-iNg+2VhYNpLrQRNdWHS09Yad7vLmOfUZKv8aJq+zkeutENIkfJaKNUERHMtpjONl0aKFFXwqSbUxY8tmmdgSqw==
4390+
travels@^0.5.2:
4391+
version "0.5.2"
4392+
resolved "https://registry.yarnpkg.com/travels/-/travels-0.5.2.tgz#25d167d9feb2bce987bdb463c69bf98852456090"
4393+
integrity sha512-2cr4HJ02keoD1DrGCjhguKY2j55ySKkrFGZpZT9u264orhQd+Df6njXOUcFEHGxfoKBOwXlHK+RJ2IKlLYjTeQ==
43944394

43954395
trim-lines@^3.0.0:
43964396
version "3.0.1"

0 commit comments

Comments
 (0)