-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Merging type only namespace and const in module declaration #63349
Description
Acknowledgement
- I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
I'm trying to create a type only package that describes modules exposed by the
JavaScript runtime. These modules have a default export and my goal is for the
users to be able to import the namespaces that are both the runtime value and a
type only namespace.
declare module "gi://Gtk?version=4.0" {
namespace Gtk {
namespace Class {
interface Signals {
event(): void;
}
}
interface ClassClass {
new (): Class;
}
interface Class {
field: string;
}
interface $Exports {
"0_Invalid_id": string;
Class: ClassClass;
}
}
const Gtk: Gtk.$Exports;
export default Gtk;
}import Gtk from "gi://Gtk?version=4.0";
type C = Gtk.Class;
const c = new Gtk.Class();The issue is that I want the module declaration to be augmentable from user code
which this example is not, since the namespace is not directly exported.
Exporting it however breaks user code.
declare module "gi://Gtk?version=4.0" {
export namespace Gtk {}
}
import Gtk from "gi://Gtk?version=4.0";
type C = Gtk.Class; // breaks this line, because Gtk is now value only
const c = new Gtk.Class();I found a hack using import-equals statements that makes it work, however it
causes LSP misbehaviors which I would like to avoid.
declare module "gi://Gtk?version=4.0" {
export namespace GtkNamespace {}
import Gtk = GtkNamespace;
const Gtk: Gtk.$Exports;
export default Gtk;
}User code works as expected, and the module is augmentable, however this breaks
LSP autocompletion when using the namespace as a type.
type C = Gtk. // LSP no longer autocompletesIs it possible to have the default export be the type (namespace) and value
(const) at the same time while being augmentable without breaking the LSP?
I tried vtsls and tsgo in neovim.
- tsgo (commit 6e4164e02794ceb83b23e2a6893b792865acb9e9)
- vscode-languageserver@9.0.1
I also tried it in a fresh install of vscode and zed and got the same results.