#In `d.ts` how do I create a global typed by a namespace?

1 messages · Page 1 of 1 (latest)

sturdy lagoon
#

I have a native JS library statically imported (npm is not an option) that I've written types for. The library provides all of it's interface through a global var, so I want to do something along the lines of:

export declare namespace Foo {
    // ... all my types, classes, consts, vars etc.
}

declare global {
    const foo: Foo
}

no matter which variation I tried, I end up in typescript telling me that I cannot use a namespace as a type, and I cannot find a way to make it work as desired without using skipLibCheck: true which I believe is not a desired way to deal with an error

how do I design this properly?

shy quiver
#

-# not at pc rn so can't test so these are more suggestion than answer
what if you use typeof Foo instead, or you use an interface instead of a namespace?

#

a namespace is a value, iirc..?

sturdy lagoon
#

@shy quiver thanks for the suggestions afaik I can't use an interface (the compiler at least complains) because the namespace is a huge mix (i.e. mess) of classes, variables, functions etc., so I can't do:

interface Foo {
    class Bar() {}
}

otherwise I think you're right an interface would do

#

not sure what you mean by typeof in this context, isn't that for getting the type of a specific object? I have though tried if I could do things as import type FooX = Foo then setting const foo: FooX, but to no avail, not sure if I did it right though

shy quiver
shy quiver
#

so literally a global namespace