-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Description
I didn't find any similar issue.
Consider an application where you want to enable end-user developers to extend your functionality with plugins. A plugin might mean implementing a given interface for a module, class, or package. Ideally, the plugin developer can write in javascript so the barrier to entry is lower than with typescript. However, it would still be advantageous for the plugin developer to get type hints and type checking even though the file may not live in the application codebase.
One solution I've seen is to generate boilerplate, but that is a heavy-handed solution when the end user "just" needs to fill out the implementation of a javascript function.
You can also specify JsDoc but that adds noise to the file you need to edit and has an additional maintenance burden if you already have typescript.
I'm proposing vscode support typechecking javascript source files against an externally referenced .d.ts definition to ensure the developer is building something that meets the expected interface without needing to run a build process or download additional dependencies (outside of the typescript that vscode uses).
I'm imagining this can be done with something similar to https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html but for javascript files instead of typescript files.
plugin.d.ts (provided by application authors at some url e.g. https://example.com/plugin.d.ts)
type PluginInput = {
name: string
}
interface MyPlugin {
doSomething(input: PluginInput): void
}
export = MyPlugin
plugin-implementation.js (initial boilerplate provided by application authors to build on for this use case)
// the js code should implement the interface from the .d.ts file
/// <reference types="https://example.com/plugin.d.ts" />
export default class MyPlugin {
doSomething(input) {
// plugin author sees autocomplete and type issues when filling out this body
console.log(input.name.length);
}
}
Is this feasible? How might it be implemented? Please let me know if this isn't the best place to discuss this, or if you need additional information. Thanks for the great work on vscode!