Typescript with React Native, Graphql and Formik in One Screen












0














I am trying to use typescript together with React Native, Graphql and Formik.



I get a red squiggly line under EmailSignupScreen ( export default graphql(SIGNUP_MUTATION)(EmailSignupScreen); with the following error message



Argument of type 'typeof EmailSignupScreen' is not assignable to parameter of type 'ComponentType<Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>>'.
Type 'typeof EmailSignupScreen' is not assignable to type 'ComponentClass<Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>, any>'.
Types of parameters 'props' and 'props' are incompatible.
Type 'Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>' is not assignable to type 'Readonly<FormikSharedConfig & FormikState<FormValues> & FormikActions<FormValues> & FormikHandlers & FormikComputedProps<FormValues> & FormikRegistration & MutateProps<{}, OperationVariables> & Props>'.
Property 'values' is missing in type 'Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>'.


I suspect the error lies in this line of code ...



class EmailSignupScreen extends Component<
ChildMutateProps<FormikProps<FormValues>> & Props
>


How should I properly type in using typescript to get rid of the error



Thank you



import React, { Component } from "react";
import { View, Text, StyleSheet, Alert, TouchableOpacity } from "react-native";
import { Button } from "react-native-elements";
import { Formik, FormikProps } from "formik";
import { NavigationScreenProp } from "react-navigation";
import * as Yup from "yup";

import Input from "../components/Input";
import SIGNUP_MUTATION from "../graphql/mutations/signup";
import { graphql, ChildMutateProps } from "react-apollo";

interface Props {
navigation: NavigationScreenProp<any, any>;
}

interface FormValues {
email: string;
password: string;
confirmPassword: string;
}

const api = (user: any) =>
new Promise((resolve, reject) => {
setTimeout(() => {
if (user.email === "hello@gmail.com") {
reject({ email: "Email already use" });
} else {
resolve();
}
}, 2000);
});

class EmailSignupScreen extends Component<
ChildMutateProps<FormikProps<FormValues>> & Props
> {
static navigationOptions = () => ({
title: "SIGN UP"
});

_handleSubmit = async (values: any, bag: any) => {
try {
await api(values);
Alert.alert("Successful!");
} catch (error) {
bag.setSubmitting(false);
bag.setErrors(error);
}
};
render() {
const { container, buttonStyle, linkStyle } = styles;
return (
<View style={container}>
<Formik
initialValues={{ email: "", password: "", confirmPassword: "" }}
onSubmit={this._handleSubmit}
validationSchema={Yup.object().shape({
email: Yup.string()
.email("Not valid email")
.required("Email is required"),
password: Yup.string()
.min(6)
.required("Password is required"),
confirmPassword: Yup.string()
.oneOf(
[Yup.ref("password", undefined)],
"Confirm Password must matched Password"
)
.required("Confirm Password is required")
})}
render={({
values,
handleSubmit,
errors,
touched,
setFieldValue,
setFieldTouched,
isValid,
isSubmitting
}: any) => (
<React.Fragment>
<Input
label="Email"
autoCapitalize="none"
autoComplete="none"
value={values.email}
onChange={setFieldValue}
onTouch={setFieldTouched}
name="email"
error={touched.email && errors.email}
/>
<Input
label="Password"
autoComplete={false}
autoCapitalize="none"
secureTextEntry
name="password"
value={values.password}
onChange={setFieldValue}
onTouch={setFieldTouched}
error={touched.password && errors.password}
/>
<Input
label="Confirm Password"
autoComplete={false}
autoCapitalize="none"
secureTextEntry
name="confirmPassword"
value={values.confirmPassword}
onChange={setFieldValue}
onTouch={setFieldTouched}
error={touched.confirmPassword && errors.confirmPassword}
/>
<Button
backgroundColor="purple"
buttonStyle={buttonStyle}
title="Submit"
onPress={handleSubmit}
disabled={!isValid || isSubmitting}
loading={isSubmitting}
/>
<TouchableOpacity
style={linkStyle}
onPress={() => this.props.navigation.navigate("Signin")}
>
<Text>Go to Sign in</Text>
</TouchableOpacity>
</React.Fragment>
)}
/>
</View>
);
}
}

export default graphql(SIGNUP_MUTATION)(EmailSignupScreen);









share|improve this question





























    0














    I am trying to use typescript together with React Native, Graphql and Formik.



    I get a red squiggly line under EmailSignupScreen ( export default graphql(SIGNUP_MUTATION)(EmailSignupScreen); with the following error message



    Argument of type 'typeof EmailSignupScreen' is not assignable to parameter of type 'ComponentType<Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>>'.
    Type 'typeof EmailSignupScreen' is not assignable to type 'ComponentClass<Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>, any>'.
    Types of parameters 'props' and 'props' are incompatible.
    Type 'Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>' is not assignable to type 'Readonly<FormikSharedConfig & FormikState<FormValues> & FormikActions<FormValues> & FormikHandlers & FormikComputedProps<FormValues> & FormikRegistration & MutateProps<{}, OperationVariables> & Props>'.
    Property 'values' is missing in type 'Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>'.


    I suspect the error lies in this line of code ...



    class EmailSignupScreen extends Component<
    ChildMutateProps<FormikProps<FormValues>> & Props
    >


    How should I properly type in using typescript to get rid of the error



    Thank you



    import React, { Component } from "react";
    import { View, Text, StyleSheet, Alert, TouchableOpacity } from "react-native";
    import { Button } from "react-native-elements";
    import { Formik, FormikProps } from "formik";
    import { NavigationScreenProp } from "react-navigation";
    import * as Yup from "yup";

    import Input from "../components/Input";
    import SIGNUP_MUTATION from "../graphql/mutations/signup";
    import { graphql, ChildMutateProps } from "react-apollo";

    interface Props {
    navigation: NavigationScreenProp<any, any>;
    }

    interface FormValues {
    email: string;
    password: string;
    confirmPassword: string;
    }

    const api = (user: any) =>
    new Promise((resolve, reject) => {
    setTimeout(() => {
    if (user.email === "hello@gmail.com") {
    reject({ email: "Email already use" });
    } else {
    resolve();
    }
    }, 2000);
    });

    class EmailSignupScreen extends Component<
    ChildMutateProps<FormikProps<FormValues>> & Props
    > {
    static navigationOptions = () => ({
    title: "SIGN UP"
    });

    _handleSubmit = async (values: any, bag: any) => {
    try {
    await api(values);
    Alert.alert("Successful!");
    } catch (error) {
    bag.setSubmitting(false);
    bag.setErrors(error);
    }
    };
    render() {
    const { container, buttonStyle, linkStyle } = styles;
    return (
    <View style={container}>
    <Formik
    initialValues={{ email: "", password: "", confirmPassword: "" }}
    onSubmit={this._handleSubmit}
    validationSchema={Yup.object().shape({
    email: Yup.string()
    .email("Not valid email")
    .required("Email is required"),
    password: Yup.string()
    .min(6)
    .required("Password is required"),
    confirmPassword: Yup.string()
    .oneOf(
    [Yup.ref("password", undefined)],
    "Confirm Password must matched Password"
    )
    .required("Confirm Password is required")
    })}
    render={({
    values,
    handleSubmit,
    errors,
    touched,
    setFieldValue,
    setFieldTouched,
    isValid,
    isSubmitting
    }: any) => (
    <React.Fragment>
    <Input
    label="Email"
    autoCapitalize="none"
    autoComplete="none"
    value={values.email}
    onChange={setFieldValue}
    onTouch={setFieldTouched}
    name="email"
    error={touched.email && errors.email}
    />
    <Input
    label="Password"
    autoComplete={false}
    autoCapitalize="none"
    secureTextEntry
    name="password"
    value={values.password}
    onChange={setFieldValue}
    onTouch={setFieldTouched}
    error={touched.password && errors.password}
    />
    <Input
    label="Confirm Password"
    autoComplete={false}
    autoCapitalize="none"
    secureTextEntry
    name="confirmPassword"
    value={values.confirmPassword}
    onChange={setFieldValue}
    onTouch={setFieldTouched}
    error={touched.confirmPassword && errors.confirmPassword}
    />
    <Button
    backgroundColor="purple"
    buttonStyle={buttonStyle}
    title="Submit"
    onPress={handleSubmit}
    disabled={!isValid || isSubmitting}
    loading={isSubmitting}
    />
    <TouchableOpacity
    style={linkStyle}
    onPress={() => this.props.navigation.navigate("Signin")}
    >
    <Text>Go to Sign in</Text>
    </TouchableOpacity>
    </React.Fragment>
    )}
    />
    </View>
    );
    }
    }

    export default graphql(SIGNUP_MUTATION)(EmailSignupScreen);









    share|improve this question



























      0












      0








      0


      1





      I am trying to use typescript together with React Native, Graphql and Formik.



      I get a red squiggly line under EmailSignupScreen ( export default graphql(SIGNUP_MUTATION)(EmailSignupScreen); with the following error message



      Argument of type 'typeof EmailSignupScreen' is not assignable to parameter of type 'ComponentType<Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>>'.
      Type 'typeof EmailSignupScreen' is not assignable to type 'ComponentClass<Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>, any>'.
      Types of parameters 'props' and 'props' are incompatible.
      Type 'Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>' is not assignable to type 'Readonly<FormikSharedConfig & FormikState<FormValues> & FormikActions<FormValues> & FormikHandlers & FormikComputedProps<FormValues> & FormikRegistration & MutateProps<{}, OperationVariables> & Props>'.
      Property 'values' is missing in type 'Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>'.


      I suspect the error lies in this line of code ...



      class EmailSignupScreen extends Component<
      ChildMutateProps<FormikProps<FormValues>> & Props
      >


      How should I properly type in using typescript to get rid of the error



      Thank you



      import React, { Component } from "react";
      import { View, Text, StyleSheet, Alert, TouchableOpacity } from "react-native";
      import { Button } from "react-native-elements";
      import { Formik, FormikProps } from "formik";
      import { NavigationScreenProp } from "react-navigation";
      import * as Yup from "yup";

      import Input from "../components/Input";
      import SIGNUP_MUTATION from "../graphql/mutations/signup";
      import { graphql, ChildMutateProps } from "react-apollo";

      interface Props {
      navigation: NavigationScreenProp<any, any>;
      }

      interface FormValues {
      email: string;
      password: string;
      confirmPassword: string;
      }

      const api = (user: any) =>
      new Promise((resolve, reject) => {
      setTimeout(() => {
      if (user.email === "hello@gmail.com") {
      reject({ email: "Email already use" });
      } else {
      resolve();
      }
      }, 2000);
      });

      class EmailSignupScreen extends Component<
      ChildMutateProps<FormikProps<FormValues>> & Props
      > {
      static navigationOptions = () => ({
      title: "SIGN UP"
      });

      _handleSubmit = async (values: any, bag: any) => {
      try {
      await api(values);
      Alert.alert("Successful!");
      } catch (error) {
      bag.setSubmitting(false);
      bag.setErrors(error);
      }
      };
      render() {
      const { container, buttonStyle, linkStyle } = styles;
      return (
      <View style={container}>
      <Formik
      initialValues={{ email: "", password: "", confirmPassword: "" }}
      onSubmit={this._handleSubmit}
      validationSchema={Yup.object().shape({
      email: Yup.string()
      .email("Not valid email")
      .required("Email is required"),
      password: Yup.string()
      .min(6)
      .required("Password is required"),
      confirmPassword: Yup.string()
      .oneOf(
      [Yup.ref("password", undefined)],
      "Confirm Password must matched Password"
      )
      .required("Confirm Password is required")
      })}
      render={({
      values,
      handleSubmit,
      errors,
      touched,
      setFieldValue,
      setFieldTouched,
      isValid,
      isSubmitting
      }: any) => (
      <React.Fragment>
      <Input
      label="Email"
      autoCapitalize="none"
      autoComplete="none"
      value={values.email}
      onChange={setFieldValue}
      onTouch={setFieldTouched}
      name="email"
      error={touched.email && errors.email}
      />
      <Input
      label="Password"
      autoComplete={false}
      autoCapitalize="none"
      secureTextEntry
      name="password"
      value={values.password}
      onChange={setFieldValue}
      onTouch={setFieldTouched}
      error={touched.password && errors.password}
      />
      <Input
      label="Confirm Password"
      autoComplete={false}
      autoCapitalize="none"
      secureTextEntry
      name="confirmPassword"
      value={values.confirmPassword}
      onChange={setFieldValue}
      onTouch={setFieldTouched}
      error={touched.confirmPassword && errors.confirmPassword}
      />
      <Button
      backgroundColor="purple"
      buttonStyle={buttonStyle}
      title="Submit"
      onPress={handleSubmit}
      disabled={!isValid || isSubmitting}
      loading={isSubmitting}
      />
      <TouchableOpacity
      style={linkStyle}
      onPress={() => this.props.navigation.navigate("Signin")}
      >
      <Text>Go to Sign in</Text>
      </TouchableOpacity>
      </React.Fragment>
      )}
      />
      </View>
      );
      }
      }

      export default graphql(SIGNUP_MUTATION)(EmailSignupScreen);









      share|improve this question















      I am trying to use typescript together with React Native, Graphql and Formik.



      I get a red squiggly line under EmailSignupScreen ( export default graphql(SIGNUP_MUTATION)(EmailSignupScreen); with the following error message



      Argument of type 'typeof EmailSignupScreen' is not assignable to parameter of type 'ComponentType<Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>>'.
      Type 'typeof EmailSignupScreen' is not assignable to type 'ComponentClass<Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>, any>'.
      Types of parameters 'props' and 'props' are incompatible.
      Type 'Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>' is not assignable to type 'Readonly<FormikSharedConfig & FormikState<FormValues> & FormikActions<FormValues> & FormikHandlers & FormikComputedProps<FormValues> & FormikRegistration & MutateProps<{}, OperationVariables> & Props>'.
      Property 'values' is missing in type 'Partial<DataProps<{}, {}>> & Partial<MutateProps<{}, {}>>'.


      I suspect the error lies in this line of code ...



      class EmailSignupScreen extends Component<
      ChildMutateProps<FormikProps<FormValues>> & Props
      >


      How should I properly type in using typescript to get rid of the error



      Thank you



      import React, { Component } from "react";
      import { View, Text, StyleSheet, Alert, TouchableOpacity } from "react-native";
      import { Button } from "react-native-elements";
      import { Formik, FormikProps } from "formik";
      import { NavigationScreenProp } from "react-navigation";
      import * as Yup from "yup";

      import Input from "../components/Input";
      import SIGNUP_MUTATION from "../graphql/mutations/signup";
      import { graphql, ChildMutateProps } from "react-apollo";

      interface Props {
      navigation: NavigationScreenProp<any, any>;
      }

      interface FormValues {
      email: string;
      password: string;
      confirmPassword: string;
      }

      const api = (user: any) =>
      new Promise((resolve, reject) => {
      setTimeout(() => {
      if (user.email === "hello@gmail.com") {
      reject({ email: "Email already use" });
      } else {
      resolve();
      }
      }, 2000);
      });

      class EmailSignupScreen extends Component<
      ChildMutateProps<FormikProps<FormValues>> & Props
      > {
      static navigationOptions = () => ({
      title: "SIGN UP"
      });

      _handleSubmit = async (values: any, bag: any) => {
      try {
      await api(values);
      Alert.alert("Successful!");
      } catch (error) {
      bag.setSubmitting(false);
      bag.setErrors(error);
      }
      };
      render() {
      const { container, buttonStyle, linkStyle } = styles;
      return (
      <View style={container}>
      <Formik
      initialValues={{ email: "", password: "", confirmPassword: "" }}
      onSubmit={this._handleSubmit}
      validationSchema={Yup.object().shape({
      email: Yup.string()
      .email("Not valid email")
      .required("Email is required"),
      password: Yup.string()
      .min(6)
      .required("Password is required"),
      confirmPassword: Yup.string()
      .oneOf(
      [Yup.ref("password", undefined)],
      "Confirm Password must matched Password"
      )
      .required("Confirm Password is required")
      })}
      render={({
      values,
      handleSubmit,
      errors,
      touched,
      setFieldValue,
      setFieldTouched,
      isValid,
      isSubmitting
      }: any) => (
      <React.Fragment>
      <Input
      label="Email"
      autoCapitalize="none"
      autoComplete="none"
      value={values.email}
      onChange={setFieldValue}
      onTouch={setFieldTouched}
      name="email"
      error={touched.email && errors.email}
      />
      <Input
      label="Password"
      autoComplete={false}
      autoCapitalize="none"
      secureTextEntry
      name="password"
      value={values.password}
      onChange={setFieldValue}
      onTouch={setFieldTouched}
      error={touched.password && errors.password}
      />
      <Input
      label="Confirm Password"
      autoComplete={false}
      autoCapitalize="none"
      secureTextEntry
      name="confirmPassword"
      value={values.confirmPassword}
      onChange={setFieldValue}
      onTouch={setFieldTouched}
      error={touched.confirmPassword && errors.confirmPassword}
      />
      <Button
      backgroundColor="purple"
      buttonStyle={buttonStyle}
      title="Submit"
      onPress={handleSubmit}
      disabled={!isValid || isSubmitting}
      loading={isSubmitting}
      />
      <TouchableOpacity
      style={linkStyle}
      onPress={() => this.props.navigation.navigate("Signin")}
      >
      <Text>Go to Sign in</Text>
      </TouchableOpacity>
      </React.Fragment>
      )}
      />
      </View>
      );
      }
      }

      export default graphql(SIGNUP_MUTATION)(EmailSignupScreen);






      typescript graphql formik






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 at 1:44









      Matt McCutchen

      13.3k719




      13.3k719










      asked Nov 12 at 12:28









      Hendry Lim

      3601414




      3601414





























          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262217%2ftypescript-with-react-native-graphql-and-formik-in-one-screen%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262217%2ftypescript-with-react-native-graphql-and-formik-in-one-screen%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Bressuire

          Vorschmack

          Quarantine