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

88
Views
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 answers
Answer question

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 Report
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!