Questions tagged [.d.ts]

.d.ts is commonly used to define a typescript declaration file containing definitions for properties and functions. This gives the benefit to an IDE allowing it to provide intellisense and proper error messages when the declaration file is not adhered to.

156 questions
721
votes
10 answers

About "*.d.ts" in TypeScript

I am curious about .d.ts declaration files because I am new to the TypeScript programming language. I was told by someone that .d.ts files are are similar to .h header files in the C & C++ programming languages, however, the .d.ts files don't seem…
user3221822
75
votes
2 answers

Typescript does not copy d.ts files to build

So maybe I'm confused, but I thought that if I added declaration:true to my tsconfig.json I could have it tsc copy my *.d.ts files, along side the transpiled code & it's d.ts files? EG: - src - lib - types.d.ts - foo.ts I would expect the…
NSjonas
  • 10,693
  • 9
  • 66
  • 92
32
votes
2 answers

What are *.d.ts files for?

In many TypeScript examples files of the *.d.ts type are automatically created at build time. Some of the examples speak of ambient declarations. This though doesn't help me understanding the idea and the sense behind those files, as they basically…
Socrates
  • 8,724
  • 25
  • 66
  • 113
28
votes
3 answers

Add custom typings file in a JavaScript VSCode project

Problem I am working on JavaScript project using VSCode. I am using the UMD design pattern and vscode intellisense cannot recognize the exports of a module from another file. I added all the declarations in a file called globals.d.ts. Unfortunately…
nick zoum
  • 7,216
  • 7
  • 36
  • 80
26
votes
4 answers

Typescript interface, function and namespace all have the same name. Which is being exported?

In the Typescript definition file (DefinitelyTyped) I am examining, there is an interface, a function and a namespace all with the exact same name: twilio. Here is the sample, from the first few lines of the file: declare interface twilio { (sid?:…
CodyBugstein
  • 21,984
  • 61
  • 207
  • 363
22
votes
3 answers

Generate d.ts file for Vue components written in Typescript

I'm new to Vue and I would like to learn how to create components and publish the package to NPM. So, my idea is to create Vue (typescript) + Vuetify reusable components and install them from NPM in any other project I have. I can successfully…
20
votes
3 answers

Create react app typescript does not load d.ts file

I have created a project using create react app typescript. I have a few d.ts files where I have defined interfaces types and enums. When I run start script. It is not able to load the d.ts files. following is my tsconfig file. { …
Anurag Sharma
  • 241
  • 1
  • 2
  • 7
15
votes
3 answers

How to overwrite property for intersection type in Typescript?

Let's say I have these types: type BaseAnimal = { species: string owner: boolean } type Cat = BaseAnimal & { species: 'cat' hasTail: boolean } type Dog = BaseAnimal & { species: 'dog' likesWalks: boolean } type Animal = Cat | Dog And…
reesaspieces
  • 1,600
  • 4
  • 18
  • 47
12
votes
2 answers

When to use types.ts vs types.d.ts

There are many resources explaining a declaration file (d.ts) is useful for either: Declaring types for JS libraries used in your TS project, or Allowing your JS library to be consumed by other TS projects What confuses me is that many projects…
ale917k
  • 1,494
  • 7
  • 18
  • 37
12
votes
3 answers

Declare Interfaces in typings file for JavaScript

Project Info I'm working on a JavaScript project that utilizes .d.ts files. This is a subsequent question to a question I previously asked, so you can view more information regarding the project here. Problem Although I can normally extract…
nick zoum
  • 7,216
  • 7
  • 36
  • 80
10
votes
3 answers

How can I hide 'private' methods with JSDoc Typescript Declarations?

Let's say I have a JavaScript class /** * @element my-element */ export class MyElement extends HTMLElement { publicMethod() {} /** @private */ privateMethod() {} } customElements.define('my-element', MyElement); and a declaration file,…
Benny Powers
  • 5,398
  • 4
  • 32
  • 55
9
votes
1 answer

How to import custom file types in Typescript

As a bit of a fun project, I'm making a "framework" for creating native web components. I've created a webpack loader that parses some XML in custom .comp files and exports an es2015 class. Unfortunately, I can't find a way to import these .comp…
heavygl0w
  • 209
  • 1
  • 3
  • 7
7
votes
1 answer

Why the ES2015 module syntax is preferred over custom TypeScript namespaces?

From typescript-eslint docs: Custom TypeScript modules (module foo {}) and namespaces (namespace foo {}) are considered outdated ways to organize TypeScript code. ES2015 module syntax is now preferred (import/export). From Typescripts…
cbdeveloper
  • 27,898
  • 37
  • 155
  • 336
7
votes
2 answers

How to solve the "Could not find a declaration file for module" error using my own declaration file?

I have a test project in which I'm testing type definition files. The project has one file called index.ts which looks like this: import i18nFu = require("gettext.js"); The gettext.js package was installed using Node.js like this: npm install…
Krisztián Balla
  • 19,223
  • 13
  • 68
  • 84
6
votes
1 answer

rollup-plugin-dts leaves leftover d.ts files

Very trivial problem it seems. I have a rollup typescript config using rollup-plugin-typescript and rollup-plugin-dts. I want to bundle all my d.ts files into one d.ts file instead of having it mirroring my project structure. I followed some…
flooz
  • 143
  • 1
  • 4
1
2 3
10 11