Skip to content

Commit

Permalink
Workaround various typescript issues
Browse files Browse the repository at this point in the history
Some types are now typed 'unknown' (in particular from yield).
See microsoft/TypeScript#32523
  • Loading branch information
briot committed Jan 24, 2020
1 parent b09f65d commit a015a33
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
9 changes: 6 additions & 3 deletions src/Server/Source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ export function sourceFromJSON(s: JSON.Source) {
return result;
}

export function* fetchSourceDetailsFromServer(id: number) {
const resp: Response = yield window.fetch("/data/sources/" + id);
export function* fetchSourceDetailsFromServer(
id: number
): Generator<any, Source> {
const prom: Promise<Response> = window.fetch("/data/sources/" + id);
const resp: Response = (yield prom) as Response; // workaround typescript
if (resp.status !== 200) {
throw new Error("Server returned an error");
}
const data: JSONResult = yield resp.json();
const data: JSONResult = (yield resp.json()) as JSONResult; // workaround
let r: Source = {
...sourceFromJSON(data.source),
medias: data.repr,
Expand Down
7 changes: 3 additions & 4 deletions src/Store/Actions.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as Redux from "redux";
import {
call,
put,
Expand Down Expand Up @@ -74,9 +75,7 @@ export function createAsyncAction<Params, Result>(
allSagas.push(takeEvery(request.type, perform));

return {
started: actions.started,
done: actions.done,
failed: actions.failed,
execute
...actions, // 'started', 'done', 'failed'
execute, // dispatch the 'request' action, which executes async
};
}
2 changes: 1 addition & 1 deletion src/Store/Reducers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function rootReducer(
} else if (isType(action, changeStatsSettings)) {
return { ...state, stats: { ...state.stats, ...action.payload.diff } };
} else if (isType(action, fetchEventDetails.done)) {
const data = action.payload.result as EventDetails;
const data = action.payload.result;
const s = { ...state, ...mergeAssertionEntities(state, data) };
s.events[data.id].asserts = data.asserts;
return s;
Expand Down
11 changes: 6 additions & 5 deletions src/Store/Sagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ function _hasEventDetails(p: FetchEventDetailsParams, state: AppState) {
return p.id in state.events && state.events[p.id].asserts !== undefined;
}
function* _fetchEventDetails(p: FetchEventDetailsParams) {
const res: EventDetails = yield call(fetchEventFromServer, p.id);
return res;
return (yield call(fetchEventFromServer, p.id)) as EventDetails;
}
export const fetchEventDetails = createAsyncAction(
export const fetchEventDetails = createAsyncAction<
FetchEventDetailsParams,
EventDetails
>(
"DATA/EVENT",
_fetchEventDetails,
_hasEventDetails
Expand All @@ -104,8 +106,7 @@ function _hasSourceDetails() {
return false;
}
function* _fetchSourceDetails(p: FetchSourceDetailsParams) {
const res: Source = yield call(fetchSourceDetailsFromServer, p.id);
return res;
return (yield call(fetchSourceDetailsFromServer, p.id)) as Source;
}
export const fetchSourceDetails = createAsyncAction(
"DATA/SOURCE",
Expand Down
3 changes: 1 addition & 2 deletions src/Store/State.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export interface AppState {
sources: SourceSet;
}

export type GPDispatch = Redux.Dispatch<AppState>;
export type GPStore = Redux.Store<AppState>;
export type GPStore = Redux.Store<AppState, Redux.AnyAction>;

/**
* Given an id, returns the name of the corresponding theme.
Expand Down
4 changes: 2 additions & 2 deletions src/Store/Store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ if (process.env.NODE_ENV === `development`) {
); // log actions in the console
}

export const store: GPStore = Redux.createStore<AppState>(
export const store = Redux.createStore(
rootReducer /* reducer */,
Redux.compose(
/* enhancer */
Redux.applyMiddleware(...middlewares) as Redux.StoreEnhancer<AppState>,
Redux.applyMiddleware(...middlewares),
autoRehydrate<AppState>({ log: false }) // load from persistent storage
)
);
Expand Down

0 comments on commit a015a33

Please sign in to comment.