Fable - Cannot get type info of generic parameter, please inline or inject a type resolver





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







2















I'm trying to write a generic json decode function in fable. It seems to compile in FSharp but I get the error message for this code:



[using the Thoth.Json library and the Fetch library from Fable.PowerPack]



let autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
Result.mapError getDecoderError tryDecode


error FABLE: Cannot get type info of generic parameter, please inline or inject a type resolver



I'm not sure how to fix this and haven't been able to find anything on google.



I want to be able to call the function like this in my update function in Fable Elmish:



let update (msg:Msg) (model:Model) =
match msg with
..
| OrStart ->
let getData() = Fetch.fetchAs<ResultResponse> "https://randomuser.me/api/" json.autoDecoder<ResultResponse> http.getHeaders
model, Cmd.ofPromise getData () LoadedTypedData FetchError


How can I get fable to compile the autoDecoder<'a> function while keeping it generic?



Thanks










share|improve this question





























    2















    I'm trying to write a generic json decode function in fable. It seems to compile in FSharp but I get the error message for this code:



    [using the Thoth.Json library and the Fetch library from Fable.PowerPack]



    let autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
    let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
    let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
    Result.mapError getDecoderError tryDecode


    error FABLE: Cannot get type info of generic parameter, please inline or inject a type resolver



    I'm not sure how to fix this and haven't been able to find anything on google.



    I want to be able to call the function like this in my update function in Fable Elmish:



    let update (msg:Msg) (model:Model) =
    match msg with
    ..
    | OrStart ->
    let getData() = Fetch.fetchAs<ResultResponse> "https://randomuser.me/api/" json.autoDecoder<ResultResponse> http.getHeaders
    model, Cmd.ofPromise getData () LoadedTypedData FetchError


    How can I get fable to compile the autoDecoder<'a> function while keeping it generic?



    Thanks










    share|improve this question

























      2












      2








      2








      I'm trying to write a generic json decode function in fable. It seems to compile in FSharp but I get the error message for this code:



      [using the Thoth.Json library and the Fetch library from Fable.PowerPack]



      let autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
      let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
      let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
      Result.mapError getDecoderError tryDecode


      error FABLE: Cannot get type info of generic parameter, please inline or inject a type resolver



      I'm not sure how to fix this and haven't been able to find anything on google.



      I want to be able to call the function like this in my update function in Fable Elmish:



      let update (msg:Msg) (model:Model) =
      match msg with
      ..
      | OrStart ->
      let getData() = Fetch.fetchAs<ResultResponse> "https://randomuser.me/api/" json.autoDecoder<ResultResponse> http.getHeaders
      model, Cmd.ofPromise getData () LoadedTypedData FetchError


      How can I get fable to compile the autoDecoder<'a> function while keeping it generic?



      Thanks










      share|improve this question














      I'm trying to write a generic json decode function in fable. It seems to compile in FSharp but I get the error message for this code:



      [using the Thoth.Json library and the Fetch library from Fable.PowerPack]



      let autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
      let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
      let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
      Result.mapError getDecoderError tryDecode


      error FABLE: Cannot get type info of generic parameter, please inline or inject a type resolver



      I'm not sure how to fix this and haven't been able to find anything on google.



      I want to be able to call the function like this in my update function in Fable Elmish:



      let update (msg:Msg) (model:Model) =
      match msg with
      ..
      | OrStart ->
      let getData() = Fetch.fetchAs<ResultResponse> "https://randomuser.me/api/" json.autoDecoder<ResultResponse> http.getHeaders
      model, Cmd.ofPromise getData () LoadedTypedData FetchError


      How can I get fable to compile the autoDecoder<'a> function while keeping it generic?



      Thanks







      f# fable-f#






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 19:49









      onemorecupofcoffeeonemorecupofcoffee

      586416




      586416
























          2 Answers
          2






          active

          oldest

          votes


















          1














          I think Fable is telling you to use inline like this:



          let inline autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
          let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
          let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
          Result.mapError getDecoderError tryDecode


          That is because generic functions just like inline functions need to be instantiated for each call.



          BTW, the value parameter is not being used.



          You can also streamline the code like this:



          let inline autoDecoder<'a> (json:string) : Result<'a, Thoth.Json.Decode.DecoderError> =
          Thoth.Json.Decode.Auto.fromString<'a> json
          |> Result.mapError (fun (str:string) -> "Auto decode Error", Thoth.Json.Decode.FailMessage str)





          share|improve this answer
























          • Thanks, this is what allowed me to compile for fable; the function itself though was not working - the json came through as an empty string and I've just used the other "answer" because I didn't have the time to figure out why

            – onemorecupofcoffee
            Nov 28 '18 at 14:22



















          1














          I'm new to fable and I wasn't able to get it working, the fable compiler does not allow the auto decode without a specified type - fails here:



          Thoth.Json.Decode.Auto.fromString<'a>(str, true)


          But for anyone struggling with the fetch api in fable, this can be done with not too much boilerplate code. I couldn't get the promise to be generic, but a type specific implementation like getCustomers is quite succinct and I ended up doing something like this:



          type Msg =
          | Start
          | LoadedCustomerData of Result<QueryDataForJson, string>
          ..

          let getCustomers () = promise {
          let! response = Fetch.fetch "http://localhost:5000/spa/api/customers" http.getHeaders
          let! text = response.text()
          return Thoth.Json.Decode.Auto.fromString<QueryDataForJson>(text, true)
          }
          ..
          let update (msg:Msg) (model:Model) =
          match msg with
          | Start ->
          model, Cmd.ofPromise getCustomers () LoadedCustomerData FetchError
          | LoadedCustomerData resp ->
          match resp with
          | Ok qdj -> { model with gridData= queryDataFromJson qdj; message= "Loaded Customer Data" }, Cmd.none
          | Error str -> { model with message = str }, Cmd.none





          share|improve this answer
























            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%2f53437296%2ffable-cannot-get-type-info-of-generic-parameter-please-inline-or-inject-a-typ%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            I think Fable is telling you to use inline like this:



            let inline autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
            let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
            let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
            Result.mapError getDecoderError tryDecode


            That is because generic functions just like inline functions need to be instantiated for each call.



            BTW, the value parameter is not being used.



            You can also streamline the code like this:



            let inline autoDecoder<'a> (json:string) : Result<'a, Thoth.Json.Decode.DecoderError> =
            Thoth.Json.Decode.Auto.fromString<'a> json
            |> Result.mapError (fun (str:string) -> "Auto decode Error", Thoth.Json.Decode.FailMessage str)





            share|improve this answer
























            • Thanks, this is what allowed me to compile for fable; the function itself though was not working - the json came through as an empty string and I've just used the other "answer" because I didn't have the time to figure out why

              – onemorecupofcoffee
              Nov 28 '18 at 14:22
















            1














            I think Fable is telling you to use inline like this:



            let inline autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
            let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
            let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
            Result.mapError getDecoderError tryDecode


            That is because generic functions just like inline functions need to be instantiated for each call.



            BTW, the value parameter is not being used.



            You can also streamline the code like this:



            let inline autoDecoder<'a> (json:string) : Result<'a, Thoth.Json.Decode.DecoderError> =
            Thoth.Json.Decode.Auto.fromString<'a> json
            |> Result.mapError (fun (str:string) -> "Auto decode Error", Thoth.Json.Decode.FailMessage str)





            share|improve this answer
























            • Thanks, this is what allowed me to compile for fable; the function itself though was not working - the json came through as an empty string and I've just used the other "answer" because I didn't have the time to figure out why

              – onemorecupofcoffee
              Nov 28 '18 at 14:22














            1












            1








            1







            I think Fable is telling you to use inline like this:



            let inline autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
            let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
            let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
            Result.mapError getDecoderError tryDecode


            That is because generic functions just like inline functions need to be instantiated for each call.



            BTW, the value parameter is not being used.



            You can also streamline the code like this:



            let inline autoDecoder<'a> (json:string) : Result<'a, Thoth.Json.Decode.DecoderError> =
            Thoth.Json.Decode.Auto.fromString<'a> json
            |> Result.mapError (fun (str:string) -> "Auto decode Error", Thoth.Json.Decode.FailMessage str)





            share|improve this answer













            I think Fable is telling you to use inline like this:



            let inline autoDecoder<'a> (json:string) (value:obj) : Result<'a, Thoth.Json.Decode.DecoderError> =
            let tryDecode = Thoth.Json.Decode.Auto.fromString<'a>(json)
            let getDecoderError (str:string) : Thoth.Json.Decode.DecoderError = ( "Auto decode Error", Thoth.Json.Decode.FailMessage str)
            Result.mapError getDecoderError tryDecode


            That is because generic functions just like inline functions need to be instantiated for each call.



            BTW, the value parameter is not being used.



            You can also streamline the code like this:



            let inline autoDecoder<'a> (json:string) : Result<'a, Thoth.Json.Decode.DecoderError> =
            Thoth.Json.Decode.Auto.fromString<'a> json
            |> Result.mapError (fun (str:string) -> "Auto decode Error", Thoth.Json.Decode.FailMessage str)






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 23 '18 at 15:08









            AMieresAMieres

            3,6801611




            3,6801611













            • Thanks, this is what allowed me to compile for fable; the function itself though was not working - the json came through as an empty string and I've just used the other "answer" because I didn't have the time to figure out why

              – onemorecupofcoffee
              Nov 28 '18 at 14:22



















            • Thanks, this is what allowed me to compile for fable; the function itself though was not working - the json came through as an empty string and I've just used the other "answer" because I didn't have the time to figure out why

              – onemorecupofcoffee
              Nov 28 '18 at 14:22

















            Thanks, this is what allowed me to compile for fable; the function itself though was not working - the json came through as an empty string and I've just used the other "answer" because I didn't have the time to figure out why

            – onemorecupofcoffee
            Nov 28 '18 at 14:22





            Thanks, this is what allowed me to compile for fable; the function itself though was not working - the json came through as an empty string and I've just used the other "answer" because I didn't have the time to figure out why

            – onemorecupofcoffee
            Nov 28 '18 at 14:22













            1














            I'm new to fable and I wasn't able to get it working, the fable compiler does not allow the auto decode without a specified type - fails here:



            Thoth.Json.Decode.Auto.fromString<'a>(str, true)


            But for anyone struggling with the fetch api in fable, this can be done with not too much boilerplate code. I couldn't get the promise to be generic, but a type specific implementation like getCustomers is quite succinct and I ended up doing something like this:



            type Msg =
            | Start
            | LoadedCustomerData of Result<QueryDataForJson, string>
            ..

            let getCustomers () = promise {
            let! response = Fetch.fetch "http://localhost:5000/spa/api/customers" http.getHeaders
            let! text = response.text()
            return Thoth.Json.Decode.Auto.fromString<QueryDataForJson>(text, true)
            }
            ..
            let update (msg:Msg) (model:Model) =
            match msg with
            | Start ->
            model, Cmd.ofPromise getCustomers () LoadedCustomerData FetchError
            | LoadedCustomerData resp ->
            match resp with
            | Ok qdj -> { model with gridData= queryDataFromJson qdj; message= "Loaded Customer Data" }, Cmd.none
            | Error str -> { model with message = str }, Cmd.none





            share|improve this answer




























              1














              I'm new to fable and I wasn't able to get it working, the fable compiler does not allow the auto decode without a specified type - fails here:



              Thoth.Json.Decode.Auto.fromString<'a>(str, true)


              But for anyone struggling with the fetch api in fable, this can be done with not too much boilerplate code. I couldn't get the promise to be generic, but a type specific implementation like getCustomers is quite succinct and I ended up doing something like this:



              type Msg =
              | Start
              | LoadedCustomerData of Result<QueryDataForJson, string>
              ..

              let getCustomers () = promise {
              let! response = Fetch.fetch "http://localhost:5000/spa/api/customers" http.getHeaders
              let! text = response.text()
              return Thoth.Json.Decode.Auto.fromString<QueryDataForJson>(text, true)
              }
              ..
              let update (msg:Msg) (model:Model) =
              match msg with
              | Start ->
              model, Cmd.ofPromise getCustomers () LoadedCustomerData FetchError
              | LoadedCustomerData resp ->
              match resp with
              | Ok qdj -> { model with gridData= queryDataFromJson qdj; message= "Loaded Customer Data" }, Cmd.none
              | Error str -> { model with message = str }, Cmd.none





              share|improve this answer


























                1












                1








                1







                I'm new to fable and I wasn't able to get it working, the fable compiler does not allow the auto decode without a specified type - fails here:



                Thoth.Json.Decode.Auto.fromString<'a>(str, true)


                But for anyone struggling with the fetch api in fable, this can be done with not too much boilerplate code. I couldn't get the promise to be generic, but a type specific implementation like getCustomers is quite succinct and I ended up doing something like this:



                type Msg =
                | Start
                | LoadedCustomerData of Result<QueryDataForJson, string>
                ..

                let getCustomers () = promise {
                let! response = Fetch.fetch "http://localhost:5000/spa/api/customers" http.getHeaders
                let! text = response.text()
                return Thoth.Json.Decode.Auto.fromString<QueryDataForJson>(text, true)
                }
                ..
                let update (msg:Msg) (model:Model) =
                match msg with
                | Start ->
                model, Cmd.ofPromise getCustomers () LoadedCustomerData FetchError
                | LoadedCustomerData resp ->
                match resp with
                | Ok qdj -> { model with gridData= queryDataFromJson qdj; message= "Loaded Customer Data" }, Cmd.none
                | Error str -> { model with message = str }, Cmd.none





                share|improve this answer













                I'm new to fable and I wasn't able to get it working, the fable compiler does not allow the auto decode without a specified type - fails here:



                Thoth.Json.Decode.Auto.fromString<'a>(str, true)


                But for anyone struggling with the fetch api in fable, this can be done with not too much boilerplate code. I couldn't get the promise to be generic, but a type specific implementation like getCustomers is quite succinct and I ended up doing something like this:



                type Msg =
                | Start
                | LoadedCustomerData of Result<QueryDataForJson, string>
                ..

                let getCustomers () = promise {
                let! response = Fetch.fetch "http://localhost:5000/spa/api/customers" http.getHeaders
                let! text = response.text()
                return Thoth.Json.Decode.Auto.fromString<QueryDataForJson>(text, true)
                }
                ..
                let update (msg:Msg) (model:Model) =
                match msg with
                | Start ->
                model, Cmd.ofPromise getCustomers () LoadedCustomerData FetchError
                | LoadedCustomerData resp ->
                match resp with
                | Ok qdj -> { model with gridData= queryDataFromJson qdj; message= "Loaded Customer Data" }, Cmd.none
                | Error str -> { model with message = str }, Cmd.none






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 14:02









                onemorecupofcoffeeonemorecupofcoffee

                586416




                586416






























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53437296%2ffable-cannot-get-type-info-of-generic-parameter-please-inline-or-inject-a-typ%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

                    Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                    ComboBox Display Member on multiple fields

                    Is it possible to collect Nectar points via Trainline?