Several questions about Header File

Topics: General, Language Specification
Mar 12, 2014 at 2:10 AM
Edited Mar 12, 2014 at 2:14 AM
TypeScript's official doucment seldom talks about Header file, it only "roughly" tells us the usage of header file and we can download them when necessary from GitHub (some specific links)……

So I have several questions:

1) If I have a ts source file and I use tsc --d to compile that and a header file is created. So can I delete the ts source file but just keep the generated header file and the source file's js file?

2) How to define a header file for a js? I don't want to use tsc——because it must need a ts source file, but sometimes many projects are directly written in js files (we don't have ts files at all)?Can you guide me by providing some samples in details? You see that for the jQuery, the GitHub has defined with "interface……", but sometimes we define it like "declare class……",ect. So How? What's the general rules? I'm feeling puzzled....

3) Why should we use the header file? I still cannot understand because we can directly use a ts file instead of a header one. Can someone tell me the MOST benifits I can fetch from a header file?

4) How a header file finds out the source file and do linking compile? Is there a rule (e.g: Header file's name must be the same as that of a source file of js? or saving position rules?) E.g: After installing lib.d.ts, when we begin to use that, we can directly use that without more imports, so how the lib.d.ts finds out and link to the source file in TypeScript?

__ 5) A suggestion:Hope the document tells us a general method or way about converting a js file to a ts one manually (NOT USE ANY OTHER TOOLS) in detail steps.__
Mar 12, 2014 at 6:06 PM
1) It should be possible to do so, as the .d.ts file should represent the API of the .ts file.

2) You have to write .d.ts files by hand to create .d.ts files for JavaScript. You can find a number of examples at DefinitelyTyped: Reading through the code here should give you a start. For working with JavaScript, you'll largely be using interfaces. 'declare' may also be used, it's a way of saying that something is visible to the script but is external to the script.

3) You generally use .d.ts files to describe JavaScript libraries, or as a type information for components you've separately compiled.

4) You have to reference .d.ts files by hand. lib.d.ts is the only "automatic" one, the rest must either be part of your project your referenced by you manually.

5) I like the suggestion. We're currently working one documentation here, and that could be something we create:
Marked as answer by ProgramVolunteer on 3/12/2014 at 6:45 PM
Mar 13, 2014 at 7:46 AM
JONTUNER:Many thanks!