use typescript generics from vanilla javascript in vscode extension












0














I am creating a VSCode extension using JavaScript, and building a custom TextDocumentContentProvider which needs to have a particular signature, but described in TypeScript. It's onDidChange member must be of type Event<Uri>, which of course uses generics. Documentation about TextDocumentContentProvider can be found here: https://code.visualstudio.com/Docs/extensionAPI/vscode-api#_a-nametextdocumentcontentprovideraspan-classcodeitem-id436textdocumentcontentproviderspan



Of course in "vanilla" JavaScript, there is no such thing as generics. What is the correct thing to return in JavaScript to meet the correct signature described in TypeScript?



This is my implementation so far:



function PostWindow() {
this.onDidChange = ????;

this.provideTextDocumentContent = function(uri) {
return "test content";
}
}

exports.PostWindow = PostWindow;









share|improve this question
























  • You could write some demo code in TS which uses this API and look what TSC generated from that.
    – Mike Lischke
    Feb 10 '17 at 7:41










  • Thanks @MikeLischke, that worked. I took a working TS example and looked at the output JS that vscode compiled. I created something like this and it worked great: gist.github.com/kindohm/83070f1a6f8e0055937a2a40c158fef5
    – kindohm
    Feb 10 '17 at 14:16












  • I guess I can post my comment as answer then :-)
    – Mike Lischke
    Feb 10 '17 at 16:47
















0














I am creating a VSCode extension using JavaScript, and building a custom TextDocumentContentProvider which needs to have a particular signature, but described in TypeScript. It's onDidChange member must be of type Event<Uri>, which of course uses generics. Documentation about TextDocumentContentProvider can be found here: https://code.visualstudio.com/Docs/extensionAPI/vscode-api#_a-nametextdocumentcontentprovideraspan-classcodeitem-id436textdocumentcontentproviderspan



Of course in "vanilla" JavaScript, there is no such thing as generics. What is the correct thing to return in JavaScript to meet the correct signature described in TypeScript?



This is my implementation so far:



function PostWindow() {
this.onDidChange = ????;

this.provideTextDocumentContent = function(uri) {
return "test content";
}
}

exports.PostWindow = PostWindow;









share|improve this question
























  • You could write some demo code in TS which uses this API and look what TSC generated from that.
    – Mike Lischke
    Feb 10 '17 at 7:41










  • Thanks @MikeLischke, that worked. I took a working TS example and looked at the output JS that vscode compiled. I created something like this and it worked great: gist.github.com/kindohm/83070f1a6f8e0055937a2a40c158fef5
    – kindohm
    Feb 10 '17 at 14:16












  • I guess I can post my comment as answer then :-)
    – Mike Lischke
    Feb 10 '17 at 16:47














0












0








0







I am creating a VSCode extension using JavaScript, and building a custom TextDocumentContentProvider which needs to have a particular signature, but described in TypeScript. It's onDidChange member must be of type Event<Uri>, which of course uses generics. Documentation about TextDocumentContentProvider can be found here: https://code.visualstudio.com/Docs/extensionAPI/vscode-api#_a-nametextdocumentcontentprovideraspan-classcodeitem-id436textdocumentcontentproviderspan



Of course in "vanilla" JavaScript, there is no such thing as generics. What is the correct thing to return in JavaScript to meet the correct signature described in TypeScript?



This is my implementation so far:



function PostWindow() {
this.onDidChange = ????;

this.provideTextDocumentContent = function(uri) {
return "test content";
}
}

exports.PostWindow = PostWindow;









share|improve this question















I am creating a VSCode extension using JavaScript, and building a custom TextDocumentContentProvider which needs to have a particular signature, but described in TypeScript. It's onDidChange member must be of type Event<Uri>, which of course uses generics. Documentation about TextDocumentContentProvider can be found here: https://code.visualstudio.com/Docs/extensionAPI/vscode-api#_a-nametextdocumentcontentprovideraspan-classcodeitem-id436textdocumentcontentproviderspan



Of course in "vanilla" JavaScript, there is no such thing as generics. What is the correct thing to return in JavaScript to meet the correct signature described in TypeScript?



This is my implementation so far:



function PostWindow() {
this.onDidChange = ????;

this.provideTextDocumentContent = function(uri) {
return "test content";
}
}

exports.PostWindow = PostWindow;






javascript typescript generics visual-studio-code vscode-extensions






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 27 at 13:01









Gama11

10.8k21946




10.8k21946










asked Feb 10 '17 at 5:02









kindohm

9921035




9921035












  • You could write some demo code in TS which uses this API and look what TSC generated from that.
    – Mike Lischke
    Feb 10 '17 at 7:41










  • Thanks @MikeLischke, that worked. I took a working TS example and looked at the output JS that vscode compiled. I created something like this and it worked great: gist.github.com/kindohm/83070f1a6f8e0055937a2a40c158fef5
    – kindohm
    Feb 10 '17 at 14:16












  • I guess I can post my comment as answer then :-)
    – Mike Lischke
    Feb 10 '17 at 16:47


















  • You could write some demo code in TS which uses this API and look what TSC generated from that.
    – Mike Lischke
    Feb 10 '17 at 7:41










  • Thanks @MikeLischke, that worked. I took a working TS example and looked at the output JS that vscode compiled. I created something like this and it worked great: gist.github.com/kindohm/83070f1a6f8e0055937a2a40c158fef5
    – kindohm
    Feb 10 '17 at 14:16












  • I guess I can post my comment as answer then :-)
    – Mike Lischke
    Feb 10 '17 at 16:47
















You could write some demo code in TS which uses this API and look what TSC generated from that.
– Mike Lischke
Feb 10 '17 at 7:41




You could write some demo code in TS which uses this API and look what TSC generated from that.
– Mike Lischke
Feb 10 '17 at 7:41












Thanks @MikeLischke, that worked. I took a working TS example and looked at the output JS that vscode compiled. I created something like this and it worked great: gist.github.com/kindohm/83070f1a6f8e0055937a2a40c158fef5
– kindohm
Feb 10 '17 at 14:16






Thanks @MikeLischke, that worked. I took a working TS example and looked at the output JS that vscode compiled. I created something like this and it worked great: gist.github.com/kindohm/83070f1a6f8e0055937a2a40c158fef5
– kindohm
Feb 10 '17 at 14:16














I guess I can post my comment as answer then :-)
– Mike Lischke
Feb 10 '17 at 16:47




I guess I can post my comment as answer then :-)
– Mike Lischke
Feb 10 '17 at 16:47












1 Answer
1






active

oldest

votes


















1














Use TSC to convert TS code to JS to see how you can implement that.






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%2f42151853%2fuse-typescript-generics-from-vanilla-javascript-in-vscode-extension%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









    1














    Use TSC to convert TS code to JS to see how you can implement that.






    share|improve this answer


























      1














      Use TSC to convert TS code to JS to see how you can implement that.






      share|improve this answer
























        1












        1








        1






        Use TSC to convert TS code to JS to see how you can implement that.






        share|improve this answer












        Use TSC to convert TS code to JS to see how you can implement that.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Feb 10 '17 at 16:47









        Mike Lischke

        20.6k349101




        20.6k349101






























            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%2f42151853%2fuse-typescript-generics-from-vanilla-javascript-in-vscode-extension%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

            Mossoró

            Error while reading .h5 file using the rhdf5 package in R

            Pushsharp Apns notification error: 'InvalidToken'