3
votes

I noticed that using /// <reference path="*.js"> doesn't work. I don't understand why.

Just a clarification: I KNOW about d.ts files, and I know what value is added by creating them to decorate a js file - they allow me to enjoy type-safety even when using an external library which wasn't written in typescript.

What I don't understand is why I still have to write a d.ts file even if I'm willing to forgoe type-safety.

Let's assume, for example, that I have a big JS file I have written, which contains many function definitions. These functions have names and lists of parameters. Can't the TS compiler automatically 'declare' those functions for usage? It would be a temporary solution, but it would facilitate migrating to TypeScript so much!

Is there a reason I'm missing that this is not possible, or is it just an unimplemented feature?

1

1 Answers

8
votes

Passing a JavaScript file as a reference path won't work because references are solely used to build upon the type information for your program and a JavaScript file cannot supply this type information (although if you drop your JavaScript code into a .ts file, you'll find out how far away you are from inferring the types).

You don't have to write a .d.ts file if you don't want type checking... you just tell the compiler that you don't want type checking. For example, if you wanted to use jQuery without any type checking...

declare var $: any;

$("anything").whateverIsTypedWillBeAllowed("like this");

The first line says "I'm going to be using a var named $ and I don't care about type safety when I use it".