Acknowledgement
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 autocompletes
Is 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.
I also tried it in a fresh install of vscode and zed and got the same results.
Acknowledgement
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.
The issue is that I want the module declaration to be augmentable from user code
which this example is not, since the
namespaceis not directly exported.Exporting it however breaks user code.
I found a hack using import-equals statements that makes it work, however it
causes LSP misbehaviors which I would like to avoid.
User code works as expected, and the module is augmentable, however this breaks
LSP autocompletion when using the namespace as a type.
Is it possible to have the
default exportbe the type (namespace) and value(const) at the same time while being augmentable without breaking the LSP?
I tried
vtslsandtsgoin neovim.I also tried it in a fresh install of vscode and zed and got the same results.