Q:

About "*.d.ts" in TypeScript

I'm feeling curious about *.d.ts because I'm a newbie in TypeScript. And I was told by someone that this kind of file is something like "head file" in C++ but for JS only. But I cannot convert a pure JS file to *.d.ts file unless I forcely change the *.js to *.ts. So I have three files:
a JS file, a TS file and a *.d.ts file.

What's the relationship between them?
How can I use the *.d.ts file? Does it mean I can delete the *.ts file permanently?
If so, how can the *.d.ts file know which JS file is mapping to itself?

It would be very nice if someone can give me an example.

A:

The "d.ts" file is used to provide typescript type information about an API that's written in JavaScript. The idea is that you're using something like jQuery or underscore, an existing javascript library. You want to consume those from your typescript code.
Rather than rewriting jquery or underscore or whatever in typescript, you can instead write the d.ts file, which contains only the type annotations. Then from your typescript code you get the typescript benefits of static type checking while still using a pure JS library.

A:

d stands for Declaration Files:

When a TypeScript script gets compiled there is an option to generate
  a declaration file (with the extension .d.ts) that functions as an
  interface to the components in the compiled JavaScript. In the process
  the compiler strips away all function and method bodies and preserves
  only the signatures of the types that are exported. The resulting
  declaration file can then be used to describe the exported virtual
  TypeScript types of a JavaScript library or module when a third-party
  developer consumes it from TypeScript.
The concept of declaration files is analogous to the concept of header
  file found in C/C++.

declare module arithmetics {
    add(left: number, right: number): number;
    subtract(left: number, right: number): number;
    multiply(left: number, right: number): number;
    divide(left: number, right: number): number;
}

Type declaration files can be written by hand for existing JavaScript
  libraries, as has been done for jQuery and Node.js.
Large collections of declaration files for popular JavaScript
  libraries are hosted on GitHub in DefinitelyTyped and the Typings
  Registry. A command-line utility called typings is provided to help
  search and install declaration files from the repositories.

A:

I could not comment and thus am adding this as an answer. We had some pain trying to map existing types to a javascript library.
To map a .d.ts file to its javascript file you need to give the .d.ts file the same name as the javascript file, keep them in the same folder, and point the code that needs it to the .d.ts file.
eg: test.js and test.d.ts are in the testdir/ folder, then you import it like this in a react component:
import * as Test from "./testdir/test";

The .d.ts file was exported as a namespace like this:
export as namespace Test;

export interface TestInterface1{}
export class TestClass1{}

