Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda