diff --git a/types/proj4/index.d.ts b/types/proj4/index.d.ts index afba494556..d7d4cf1ae5 100644 --- a/types/proj4/index.d.ts +++ b/types/proj4/index.d.ts @@ -1,6 +1,7 @@ -// Type definitions for proj4 2.3 +// Type definitions for proj4 2.5 // Project: https://github.com/proj4js/proj4js // Definitions by: Denis Carriere +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace proj4 { @@ -21,9 +22,9 @@ declare namespace proj4 { ep2: number; } - interface Static { - forward(coordinates: TemplateCoordinates): number[]; - inverse(coordinates: TemplateCoordinates): number[]; + interface Converter { + forward(coordinates: T): T; + inverse(coordinates: T): T; } interface InterfaceProjection { @@ -38,6 +39,39 @@ declare namespace proj4 { inverse(coordinates: TemplateCoordinates): number[]; } + interface ProjectionDefinition { + title: string; + projName?: string; + ellps?: string; + datum?: string; + datumName?: string; + rf?: number; + lat0?: number; + lat1?: number; + lat2?: number; + lat_ts?: number; + long0?: number; + long1?: number; + long2?: number; + alpha?: number; + longc?: number; + x0?: number; + y0?: number; + k0?: number; + a?: number; + b?: number; + R_A?: true; + zone?: number; + utmSouth?: true; + datum_params?: string | number[]; + to_meter?: number; + units?: string; + from_greenwich?: number; + datumCode?: string; + natGrids?: string; + axis?: string; + } + const defaultDatum: string; function Proj(srsCode: any, callback?: any): InterfaceProjection; @@ -45,23 +79,38 @@ declare namespace proj4 { const WGS84: any; /** - * Depecrated v3 + * @deprecated v3 */ function Point(x: number, y: number, z?: number): InterfaceCoordinates; function Point(coordinates: TemplateCoordinates | string): InterfaceCoordinates; function toPoint(array: number[]): InterfaceCoordinates; - function defs(name: string, projection?: string): any; - function defs(name: string[][]): any; + function defs(name: string, projection: string | ProjectionDefinition): void; + function defs(name: string[][]): undefined[]; + function defs(name: string): ProjectionDefinition; - function transform(source: InterfaceProjection, dest: InterfaceProjection, point: TemplateCoordinates): any; + function transform( + source: InterfaceProjection, + dest: InterfaceProjection, + point: TemplateCoordinates + ): any; function mgrs(coordinates: number[], accuracy: number): string; const version: string; } -declare function proj4(fromProjection: string, toProjection?: string, coordinates?: proj4.TemplateCoordinates): proj4.Static; -declare function proj4(fromProjection: string, coordinates: proj4.TemplateCoordinates): number[]; +declare function proj4(fromProjection: string, toProjection?: string): proj4.Converter; +declare function proj4( + toProjection: string, + coordinates: T +): T; +declare function proj4( + fromProjection: string, + toProjection: string, + coordinates: T +): T; + export = proj4; +export as namespace proj4; diff --git a/types/proj4/proj4-tests.ts b/types/proj4/proj4-tests.ts index 3d1ab1ab9b..7df09014db 100644 --- a/types/proj4/proj4-tests.ts +++ b/types/proj4/proj4-tests.ts @@ -3,31 +3,55 @@ import proj4 = require('proj4'); /////////////////////////////////////////// // Tests data initialisation /////////////////////////////////////////// -const name = 'WGS84'; const epsg = { 4269: '+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees', 4326: '+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees', }; -const point1 = [-71, 41]; -const point2 = {x: 2, y: 5}; -const mgrs = "24XWT783908"; +const firstProjection = epsg[4269]; +const secondProjection = epsg[4326]; + +const pointArr = [-71, 41]; +const pointObj = { x: 2, y: 5 }; /////////////////////////////////////////// // Tests Measurement /////////////////////////////////////////// -proj4(epsg['4269'], epsg['4326'], point1); -proj4(epsg['4269'], point1); -proj4(epsg['4269'], epsg['4326']).forward(point2); -proj4(epsg['4269'], epsg['4326']).inverse(point2); +proj4(firstProjection, secondProjection, pointArr); +proj4(firstProjection, pointArr); + +// $ExpectType number[] +proj4(firstProjection, secondProjection, pointArr); +// $ExpectType { x: number; y: number; } +proj4(firstProjection, secondProjection, pointObj); + +// $ExpectType number[] +proj4(firstProjection, pointArr); +// $ExpectType { x: number; y: number; } +proj4(firstProjection, pointObj); + +// $ExpectType Converter +proj4(firstProjection, secondProjection); +// $ExpectType Converter +proj4(firstProjection); + +// $ExpectType number[] +proj4(firstProjection, secondProjection).forward(pointArr); +// $ExpectType { x: number; y: number; } +proj4(firstProjection, secondProjection).forward(pointObj); +// $ExpectType number[] +proj4(firstProjection, secondProjection).inverse(pointArr); +// $ExpectType { x: number; y: number; } +proj4(firstProjection, secondProjection).inverse(pointObj); /////////////////////////////////// // Named Projections /////////////////////////////////// -proj4.defs('WGS84', epsg['4326']); -proj4.defs([ - ['EPSG:4326', epsg['4326']], - ['EPSG:4269', epsg['4269']] -]); + +// $ExpectType ProjectionDefinition +proj4.defs('WGS84'); +proj4.defs('WGS84', secondProjection); +// $ExpectType undefined[] +proj4.defs([['EPSG:4326', secondProjection], ['EPSG:4269', firstProjection]]); proj4.defs('urn:x-ogc:def:crs:EPSG:4326', proj4.defs('EPSG:4326')); /////////////////////////////////// diff --git a/types/proj4/tsconfig.json b/types/proj4/tsconfig.json index a55659d52c..02713475d5 100644 --- a/types/proj4/tsconfig.json +++ b/types/proj4/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -20,4 +20,4 @@ "index.d.ts", "proj4-tests.ts" ] -} \ No newline at end of file +}