I am new to TypeScripts, for the most part I use the DefinitelyTyped NuGet packages to get type information for the libraries I use. Every now and then I run into a library that there are no type definitions for, in this case proj4. I managed to find a couple of proj4.d.ts-files on internet that seemed fine, but when I add this file to a folder Scripts/typings/proj4.d.ts, and then attempt to use proj4(...) in my .ts file, proj4 cant be found.
If I examine my other d.ts-files (eg knockout.d.ts), I cant really see any difference between that file and my proj4.d.ts, my file has Build Action TypeScriptCompile.
Is there something else that needs to be done to "register" the proj4.d.ts file (other than simply copying it to a folder sitting next to the existing type definition files)? I am using Visual Studio 2015 and the TypeScript 1.6.3 plugin. Here is the file that I am attempting to use proj4.d.ts from ca0v on GitHub:
declare module "proj4" {
interface Transformer {
forward: (p: Point) => Point;
inverse: (p: Point) => Point;
}
class Point {
x: number;
y: number;
constructor(x: number, y: number);
}
function Proj(a, b): Transformer;
module Proj {
export function defs(name: string): any;
export function defs(name: string, def: string): void;
export function transform(from: any, to: any, pt: Point): Point;
export function parse(sr: string): any;
}
export = Proj;
}
Finally, I solved this issue by creating a new proj4.d.ts file. This file is inspired by the jquery.d.ts and it works right out of the box (like the other type definition files that I normally use from DefinitelyTyped. There might not have been anything wrong at all with the original file that I mentioned above, just that for my setup (VS 2015/TypeScript plugin 1.6.3/No external compilation/limited knowledge on modules/imports in TypeScript) this file works better.
In order to use this file, simply copy it into /Your...scripts/typings/proj4/proj4.d.ts. This file is also on GitHub/ Stockholmsnovis/MyTypeScriptDefinitions/proj4.d.ts
disclamer: My type definition file is far from complete, just the functions from proj4 that I need right now, feel free to extend
proj4.d.ts:
And here is how you would use it, eg: myscript.ts: