Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
Specifying type for wildcard access through proxy

I am trying to allow deep, remote storage access using native JS chaining syntax. I establish a proxy to build an access chain/route, then when the end of the chain is called, we would retrieve the object from storage, access the deep property and return it. A simplified case of this type of wildcard chaining is as follows:

If we define a class as follows

class TestClass{
  private handler = {
    chain: [],
    get(target: TestClass, key: any){
      chain.push(key);
      return new Proxy(target, this);
    },
    apply(target, thisArg, argumentsList){
      const lastArg = target[this.chain[this.chain.length - 1]
      if(typeof target[lastArg] === "function")
        return target[lastArg](...argumentsList);
      console.log(this.chain);
      this.chain = [];
    }
  }

  constructor(){
    return new Proxy(this, this.handler)
  }

  actualFunction(){
    console.log("Called actual function")
  }
}

We could do something like:

let t = new TestClass();
t.a.b.c.func();

To have it log [a,b,c,func] or we could do

t.a.b.c.actualFunction()

To have it log Called actual function. The issue here is that we want to receive autocomplete and type hints using wildcard access, the only way I've found to enable this so far is to use the index definition [x: string|number|symbol]: TestClass at the top of the class. This allows wildcard access with type hints and code completion but throws a bunch of TypeScript errors within the class itself.

Optimally I could use an index definition along the lines of [x: string|number|symbol]: literalType x in keyof TestClass ? any : TestClass

Any suggestions on how to make this work are much appreciated. Additionally, design decisions/directions that may enable this easier are also welcome.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!