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

97
Vistas
Is it possibile to re-declare d.ts module?

Assuming I need to download an npm package, is it possible to override the declarations (.d.ts) of the package itself?

By creating a .d.ts file with the new types, in the main project folder I can't override the package's types. The only way to enable my types is to go and manually edit the .d.ts files of the package itself.

--- Example of the problem ---

The package I'm referring to has this declaration:

declare class FooClass<T> {
  get foo(): T;
}

The declaration is very flexible on typescript projects and I can easily handle it:

const fooInstance = new FooClass<boolean>();
console.log(fooInstance.foo);

Suppose, however, that I'm using a Javascript project (and I care about types). In that case I can't specify the type of FooClass between the brackets:

const fooInstance = new FooClass();
console.log(fooInstance.foo);

Therefore I create a file foo.d.ts:

declare class FooClass {
  get foo(): boolean;
}

However foo at compile time will not be considered boolean.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

That depends on what declarations you are trying to 'override'. As it happens, certain types of entities in TypeScript will be automatically 'merged' if declared multiple times.

Read the documentation on declaration merging for more information.

about 4 years ago · Juan Pablo Isaza Denunciar
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