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

132
Views
make .d.ts for external library file available for project

I have a closed-source plain JS library that will be included via a <script> tag pointing to a CDN. I would like to author my own type definition file for this library so I can reference a global object that the library provides once loaded into the HTML page.

So far I am having trouble getting my IDE to show me that it recognizes the .d.ts file.

I have the following project structure:

project-folder/
 - tsconfig.json
 - src/
definitions/
- mylibrary.d.ts

In tsconfig I have the following:

{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ESNext", "DOM"],
    "moduleResolution": "Node",
    "strict": true,
    "sourceMap": true,
    "resolveJsonModule": true,
    "esModuleInterop": true,
    "noEmit": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "typeRoots": ["../definitions/"]
  },
  "include": ["./src"]
}

In mylibrary.d.ts I have the following:

interface example {
  hello: boolean;
}

declare namespace MyLibraryObject {
    const testing: string; 
    function foo(bar: string): void;
}

Then in main.ts I attempt to use any of the types defined in the d.ts file such as:

const test: example = { hello: true };

console.log(MyLibraryObject.testing);
MyLibaryObject.foo();

But TS cannot find the definitions for these, as seen here:

screenshot of TS errors in vscode

What can I do to resolve this?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I figured it out, the solution was to expand the set of "included" paths in the tsconfig file.

{
  "compilerOptions": {
    ...
    "typeRoots": ["../definitions/"]
  },
  "include": ["./src", "../definitions/"]
}
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!