How to get intellisense for external javascript libraries with es5 and Visual Studio Code











up vote
0
down vote

favorite












I am working with project without transpilers. When I want to use external library and use intellisense in Visual Studio Code I would need to use import (which would not work with es5).



Example: I want to use axios library so I install it with npm, add script tag reference to axios.js and write the application code in app.js. I can get intellisense when I do this



import axios from 'axios';



but it would fail with es5.



I did find a hacky workaround that gives me intellisense would and not fail with es5:



var axios = axios || require('axios').default;



But at least for me this looks too hacky to me just for intellisense :)



I also noticed that for example jquery intellisense also works without import and think the reason is that jquery type definition file does not use module syntax (export) and things are added into global scope. So I am also wondering would it be somehow possible to create my own type definition file to add things into global scope?










share|improve this question




























    up vote
    0
    down vote

    favorite












    I am working with project without transpilers. When I want to use external library and use intellisense in Visual Studio Code I would need to use import (which would not work with es5).



    Example: I want to use axios library so I install it with npm, add script tag reference to axios.js and write the application code in app.js. I can get intellisense when I do this



    import axios from 'axios';



    but it would fail with es5.



    I did find a hacky workaround that gives me intellisense would and not fail with es5:



    var axios = axios || require('axios').default;



    But at least for me this looks too hacky to me just for intellisense :)



    I also noticed that for example jquery intellisense also works without import and think the reason is that jquery type definition file does not use module syntax (export) and things are added into global scope. So I am also wondering would it be somehow possible to create my own type definition file to add things into global scope?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am working with project without transpilers. When I want to use external library and use intellisense in Visual Studio Code I would need to use import (which would not work with es5).



      Example: I want to use axios library so I install it with npm, add script tag reference to axios.js and write the application code in app.js. I can get intellisense when I do this



      import axios from 'axios';



      but it would fail with es5.



      I did find a hacky workaround that gives me intellisense would and not fail with es5:



      var axios = axios || require('axios').default;



      But at least for me this looks too hacky to me just for intellisense :)



      I also noticed that for example jquery intellisense also works without import and think the reason is that jquery type definition file does not use module syntax (export) and things are added into global scope. So I am also wondering would it be somehow possible to create my own type definition file to add things into global scope?










      share|improve this question















      I am working with project without transpilers. When I want to use external library and use intellisense in Visual Studio Code I would need to use import (which would not work with es5).



      Example: I want to use axios library so I install it with npm, add script tag reference to axios.js and write the application code in app.js. I can get intellisense when I do this



      import axios from 'axios';



      but it would fail with es5.



      I did find a hacky workaround that gives me intellisense would and not fail with es5:



      var axios = axios || require('axios').default;



      But at least for me this looks too hacky to me just for intellisense :)



      I also noticed that for example jquery intellisense also works without import and think the reason is that jquery type definition file does not use module syntax (export) and things are added into global scope. So I am also wondering would it be somehow possible to create my own type definition file to add things into global scope?







      visual-studio-code






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 at 13:32









      runnerpaul

      547323




      547323










      asked Nov 19 at 11:45









      realmer

      12




      12
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:



          Create file global.d.ts (name does not matter) in your project with following contents:



          import { AxiosStatic } from "axios";

          declare global {
          const axios: AxiosStatic;
          }


          That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))



          I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)






          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',
            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%2f53373960%2fhow-to-get-intellisense-for-external-javascript-libraries-with-es5-and-visual-st%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:



            Create file global.d.ts (name does not matter) in your project with following contents:



            import { AxiosStatic } from "axios";

            declare global {
            const axios: AxiosStatic;
            }


            That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))



            I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)






            share|improve this answer



























              up vote
              0
              down vote













              Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:



              Create file global.d.ts (name does not matter) in your project with following contents:



              import { AxiosStatic } from "axios";

              declare global {
              const axios: AxiosStatic;
              }


              That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))



              I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)






              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote









                Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:



                Create file global.d.ts (name does not matter) in your project with following contents:



                import { AxiosStatic } from "axios";

                declare global {
                const axios: AxiosStatic;
                }


                That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))



                I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)






                share|improve this answer














                Investigated this further and found out that indeed you can just create your own helper type definition file that will import types in module into global scope in order to use this in a ES5 project with global scope:



                Create file global.d.ts (name does not matter) in your project with following contents:



                import { AxiosStatic } from "axios";

                declare global {
                const axios: AxiosStatic;
                }


                That wil make intellisense work in global context (in my app.js) without having to use import. Of course only do this when you really can not use modules (global is bad :))



                I'll see if I can convince vscode people (who are imho doing excellent job with this text editor :)) that this might be useful addition to the vscode documentation as well (https://github.com/Microsoft/vscode/issues/63494)







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 20 at 11:24

























                answered Nov 20 at 10:02









                realmer

                12




                12






























                    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%2f53373960%2fhow-to-get-intellisense-for-external-javascript-libraries-with-es5-and-visual-st%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

                    Create new schema in PostgreSQL using DBeaver

                    Deepest pit of an array with Javascript: test on Codility

                    Costa Masnaga