Skip to content

Commit

Permalink
fix(ts): expand UiState mix
Browse files Browse the repository at this point in the history
an example of how it's different is:

```ts
import { Expand, UiState } from './types';

type mix = UiState & { [index: string]: { swag?: boolean } };
type mixExpand = Expand<mix>;

// @ts-expect-error
const initialUiState: mix = {
  someIndex: {
    swag: true,
  },
};

const initialUiStateExpanded: mixExpand = {
  someIndex: {
    swag: true,
  },
};
```
  • Loading branch information
Haroenv committed Aug 4, 2021
1 parent 5f8ba5d commit fb0088a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/index.es.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InstantSearchOptions, UiState } from './types';
import { Expand, InstantSearchOptions, UiState } from './types';
import InstantSearch from './lib/InstantSearch';
import version from './lib/version';
import {
Expand All @@ -15,7 +15,7 @@ const instantsearch = <
TUiState = Record<string, unknown>,
TRouteState = TUiState
>(
options: InstantSearchOptions<UiState & TUiState, TRouteState>
options: InstantSearchOptions<Expand<UiState & TUiState>, TRouteState>
) => new InstantSearch(options);

instantsearch.version = version;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/InstantSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export type InstantSearchOptions<
* for the first search. To unconditionally pass additional parameters to the
* Algolia API, take a look at the `configure` widget.
*/
initialUiState?: UiState;
initialUiState?: TUiState;

/**
* Time before a search is considered stalled. The default is 200ms
Expand Down
5 changes: 3 additions & 2 deletions src/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Expand, InstantSearchOptions, UiState } from '../types';

import InstantSearch from './InstantSearch';
import version from './version';

Expand All @@ -9,7 +11,6 @@ import * as middlewares from '../middlewares/index';
import * as routers from './routers/index';
import * as stateMappings from './stateMappings/index';
import { createInfiniteHitsSessionStorageCache } from './infiniteHitsCache/index';
import { InstantSearchOptions, UiState } from '../types';

/**
* InstantSearch is the main component of InstantSearch.js. This object
Expand All @@ -32,7 +33,7 @@ const instantsearch = <
TUiState = Record<string, unknown>,
TRouteState = TUiState
>(
options: InstantSearchOptions<UiState & TUiState, TRouteState>
options: InstantSearchOptions<Expand<UiState & TUiState>, TRouteState>
) => new InstantSearch(options);

instantsearch.routers = routers;
Expand Down

0 comments on commit fb0088a

Please sign in to comment.