Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix types

dominik-zeglen7bb18d853e81
diff --git a/saleor/static/dashboard-next/mutations.tsx b/saleor/static/dashboard-next/mutations.tsx
index f491130d55..8464684f90 100644
--- a/saleor/static/dashboard-next/mutations.tsx
+++ b/saleor/static/dashboard-next/mutations.tsx
@@ -26,32 +26,40 @@ export function TypedMutation<TData, TVariables>(
update?: MutationUpdaterFn<TData>
) {
class StrictTypedMutation extends Mutation<TData, TVariables> {}
- return ({
- children,
- onCompleted,
- onError,
- variables
- }: TypedMutationInnerProps<TData, TVariables>) => (
- <Messages>
- {pushMessage => (
- <StrictTypedMutation
- mutation={mutation}
- onCompleted={onCompleted}
- onError={err => {
- const msg = i18n.t("Something went wrong: {{ message }}", {
- message: err.message
- });
- pushMessage({ text: msg });
- if (onError) {
- onError(err);
- }
- }}
- variables={variables}
- update={update}
- >
- {children}
- </StrictTypedMutation>
- )}
- </Messages>
- );
+ return (props: TypedMutationInnerProps<TData, TVariables>) => {
+ // Obviously, this is workaround to the problem described here:
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/32588
+ const {
+ children,
+ onCompleted,
+ onError,
+ variables
+ } = props as JSX.LibraryManagedAttributes<
+ typeof StrictTypedMutation,
+ typeof props
+ >;
+ return (
+ <Messages>
+ {pushMessage => (
+ <StrictTypedMutation
+ mutation={mutation}
+ onCompleted={onCompleted}
+ onError={err => {
+ const msg = i18n.t("Something went wrong: {{ message }}", {
+ message: err.message
+ });
+ pushMessage({ text: msg });
+ if (onError) {
+ onError(err);
+ }
+ }}
+ variables={variables}
+ update={update}
+ >
+ {children}
+ </StrictTypedMutation>
+ )}
+ </Messages>
+ );
+ };
}
diff --git a/saleor/static/dashboard-next/queries.tsx b/saleor/static/dashboard-next/queries.tsx
index c06b773ccc..646036a2ab 100644
--- a/saleor/static/dashboard-next/queries.tsx
+++ b/saleor/static/dashboard-next/queries.tsx
@@ -60,89 +60,100 @@ class QueryProgress extends React.Component<QueryProgressProps, {}> {
export function TypedQuery<TData, TVariables>(query: DocumentNode) {
class StrictTypedQuery extends Query<TData, TVariables> {}
- return ({
- children,
- displayLoader,
- skip,
- variables,
- require
- }: TypedQueryInnerProps<TData, TVariables>) => (
+ return (props: TypedQueryInnerProps<TData, TVariables>) => (
<AppProgress>
{({ funcs: changeProgressState }) => (
<Navigator>
{navigate => (
<Messages>
- {pushMessage => (
- <StrictTypedQuery
- fetchPolicy="cache-and-network"
- query={query}
- variables={variables}
- skip={skip}
- context={{ useBatching: true }}
- >
- {queryData => {
- if (queryData.error) {
- const msg = i18n.t(
- "Something went wrong: {{ message }}",
- {
- message: queryData.error.message
- }
- );
- pushMessage({ text: msg });
- }
-
- const loadMore = (
- mergeFunc: (
- previousResults: TData,
- fetchMoreResult: TData
- ) => TData,
- extraVariables: RequireAtLeastOne<TVariables>
- ) =>
- queryData.fetchMore({
- query,
- updateQuery: (previousResults, { fetchMoreResult }) => {
- if (!fetchMoreResult) {
- return previousResults;
+ {pushMessage => {
+ // Obviously, this is workaround to the problem described here:
+ // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/32588
+ const {
+ children,
+ displayLoader,
+ skip,
+ variables,
+ require
+ } = props as JSX.LibraryManagedAttributes<
+ typeof StrictTypedQuery,
+ typeof props
+ >;
+ return (
+ <StrictTypedQuery
+ fetchPolicy="cache-and-network"
+ query={query}
+ variables={variables}
+ skip={skip}
+ context={{ useBatching: true }}
+ >
+ {queryData => {
+ if (queryData.error) {
+ const msg = i18n.t(
+ "Something went wrong: {{ message }}",
+ {
+ message: queryData.error.message
}
- return mergeFunc(previousResults, fetchMoreResult);
- },
- variables: { ...variables, ...extraVariables }
- });
+ );
+ pushMessage({ text: msg });
+ }
- let childrenOrNotFound = children({
- ...queryData,
- loadMore
- });
- if (
- !queryData.loading &&
- require &&
- queryData.data &&
- !require.reduce(
- (acc, key) => acc && queryData.data[key] !== null,
- true
- )
- ) {
- childrenOrNotFound = (
- <ErrorPage onBack={() => navigate("/")} />
- );
- }
+ const loadMore = (
+ mergeFunc: (
+ previousResults: TData,
+ fetchMoreResult: TData
+ ) => TData,
+ extraVariables: RequireAtLeastOne<TVariables>
+ ) =>
+ queryData.fetchMore({
+ query,
+ updateQuery: (
+ previousResults,
+ { fetchMoreResult }
+ ) => {
+ if (!fetchMoreResult) {
+ return previousResults;
+ }
+ return mergeFunc(previousResults, fetchMoreResult);
+ },
+ variables: { ...variables, ...extraVariables }
+ });
+
+ let childrenOrNotFound = children({
+ ...queryData,
+ loadMore
+ });
+ if (
+ !queryData.loading &&
+ require &&
+ queryData.data &&
+ !require.reduce(
+ (acc, key) => acc && queryData.data[key] !== null,
+ true
+ )
+ ) {
+ childrenOrNotFound = (
+ <ErrorPage onBack={() => navigate("/")} />
+ );
+ }
- if (displayLoader) {
- return (
- <QueryProgress
- loading={queryData.loading}
- onCompleted={changeProgressState.disable}
- onLoading={changeProgressState.enable}
- >
- {childrenOrNotFound}
- </QueryProgress>
- );
- }
+ if (displayLoader) {
+ return (
+ <QueryProgress
+ loading={queryData.loading}
+ onCompleted={changeProgressState.disable}
+ onLoading={changeProgressState.enable}
+ >
+ {childrenOrNotFound}
+ </QueryProgress>
+ );
+ }
- return childrenOrNotFound;
- }}
- </StrictTypedQuery>
- )}
+ return childrenOrNotFound;
+ }}
+ </StrictTypedQuery>
+ );
+ }}
</Messages>
)}
</Navigator>