#Simplifying Declare Global
14 messages · Page 1 of 1 (latest)
type Lib = typeof lib;
declare global {
[P in keyof Lib]: Lib[P];
}
Also why you need then to be global?
I don't think that works?
As for why, I'm doing some unconventional stuffs and adding them to global is easier for the consumer of my library.
It does for the global augumentation
Nope... ts is very unhapy about this.
Preview:```ts
type Lib = typeof lib;
declare global {
[P in keyof Lib]: Lib[P];
}
const lib = { a: 1, b: "" }
globalThis.a;
export {}```
Yeah declare global is not an object expression, it's a block statement.
I was thinking there's an interface for globalThis that I could declaration merge into, but the few ones I've tried didn't seem to work.
This is for Node.js btw, if that changes things.
would it be easy enough for consumers of your library to access them under a single root object? if so you could do this:
declare global {
const stuff: typeof lib
}
and users can do stuff.foo. that might be better in terms of minimizing global namespace pollution anyway
(but there's a good chance you already considered this and ruled it out)