Stack Exchange
How to declare a nested namespace from string in typescript
export const AssetHelper = (input: InputProto, type: AssetType) => {
    const name: string = AssetTypeCongig.getName(type)
    const encoded = XX[name].Proto.InputProto.encode(input).finish()
    const output = DoSothing.sign(encoded, type);
    return XX[name].Proto.OutputProto.decode(output)
};

the above code gives me the following error
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof XX'
/** Namespace XX. */
export namespace XX {

    /** Namespace Blue. */
    namespace Blue {

        /** Namespace Proto. */
        namespace Proto {

How do declare this with typescript?

Please consider modifying the code in this question so as to constitute a [mcve] which, when dropped into a standalone IDE like The TypeScript Playground (link to code), clearly demonstrates the issue you are facing (what is InputProto? what is AssetType? what is AssetTypeCongig? etc).  This will allow those who want to help you to immediately get to work solving the problem without first needing to re-create it.  And it will make it so that any answer you get is testable against a well-defined use case.

Maybe you're looking for something like this?  If so I can turn it into an answer; but I had to heavily modify your example to even get close to something demonstrable.  If you can work on getting a true [mcve] then I can be more confident about the answer.  If I'm missing something, let me know.

Hi thank you for you initial answer. i'll need to get back to the code and have a look and see if it works. Unfortunately producing something that can run its hard because AssetTypeCongig (misspelled lol) comes from a n-api function and all Proto related are from files generated from protobuf.js. Looking at your code that doesn't produce errors i believe there may be a problem with how types are named and imported, as the code should theoretically just work like yours. Only difference is InputProto And output are classes and not namespaces

All you need to do for the question is come up with something that demonstrates the problem you’re having; it should be a toy example and doesn’t have to be an excerpt of your actual code.  The point of the [mcve] is to be a problem that, if solved, would help you (and future readers) fix the analogous issue in your (their) actual code.  Of course if every attempt at a [mcve] produces working code, then as you said the issue may be something specific to your local environment, at which point you should start describing that (but it’s less likely folks can help you remotely)

Here you see the error in action https://tsplay.dev/N9AR3N

Your issue is that you are not exporting your inner namespaces and you are explicitly annotating name as string instead of allowing the compiler to infer it as the union of string literals.  But I see lots of errors in that code, most of which are seemingly unrelated to your question (missing a constructor implementation, using undeclared Long type, using undeclared $protobuf value, etc etc); I would have to modify this version even more than your original to get something that compiles without errors.  Please try to produce a [mcve] and I would be happy to give an actual answer.

@jcalz Your issue is that you are not exporting your inner namespaces and you are explicitly annotating name as string instead of allowing the compiler to infer it as the union of string literals That is it the other errors are obviously because i'm not adding everything else that missing witch is irrelevant.

I think we agree on the situation but maybe not the next steps?  I'm saying that for example code to be good for Stack Overflow, it should be a [mcve] that demonstrates the problem without having other issues that distract from it.  And so I'm asking you to modify your code so that only the relevant issue is present; other errors should be removed.  If you don't want to do that, do you mind if I edit the question to do so?  My goal here is to have a good Q/A pair that helps future readers.

@jcalz feel free to edit the question to suite your minimal reproducible example
