简体   繁体   中英

use typescript generics from vanilla javascript in vscode extension

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;

使用TSC将TS代码转换为JS,以了解如何实现。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM