Turf: Typings for @turf/distance

Created on 13 Jan 2019  路  13Comments  路  Source: Turfjs/turf

Hi! It seems that typings for distance do not work out-of-the-box.

STR:

  1. npm install --save @turf
  2. import distance from '@turf/distance';

Compiler says:

Type error: Could not find a declaration file for module '@turf/distance'. 'src/node_modules/@turf/distance/index.js' implicitly has an 'any' type.
  Try `npm install @types/turf__distance` if it exists or add a new declaration (.d.ts) file containing `declare module '@turf/distance';`  TS7016

Though if I suppress it, no errors occur while runtime.

When I look into /distance module, there is no .ts files there:

screenshot from 2019-01-13 21-19-13

Tried the following steps to fix:

  1. npm install @types/turf__distance - 404 Not Found (as turf contains types on its own, not in types repo
  2. npm install @types/turf - old version of typings
  3. npm install @turf/turf - better, I can use typings as well as distance itself, but only in way when I import the entire turf lib. So that bundle size increased by 300kb, doesn't fit.
  4. dts-gen @turf/distance - no .ts files there to create the .d.ts file

The question is: how can I use the single @turf/distance module along with TypeScript typings?

typescript

Most helpful comment

my workaround with @turf/[email protected].

// turf-distance.d.ts
declare module "@turf/distance" {
  import { Units, Coord } from "@turf/helpers";
  function distance(from: Coord, to: Coord, options: { units?: Units }): number;
  export default distance;
}

All 13 comments

@DenisCarriere please clarify

Hi @goodwin64

Typings aren't my strength and Denis isn't involved in the project at the moment.

Can you perhaps try one of the version 5 packages available on npm? Some of the version 6 stuff was a bit experimental and wasn't tagged as an alpha unfortunantly, but the v5 stuff should be fairly stable.

Cheers
Rowan

I think the issue is just an incorrectly released version - other @turf/* packages written in ts have index.d.ts along with index.js, but @turf/distance does not.

Maybe somebody from the @turf team could re-release this package only?

image

It is not a packaging issue, the files was removed with this commit
https://github.com/Turfjs/turf/commit/5fab0fe342b264d8b20a515dc55539191b4fdabe#diff-6d071eff6c43993c40d93a8b2b275048

It is unclear why.

image

The index.d.ts was removed because the code itself is written in typescript now (index.ts), which should be translated into index.js + index.d.ts during packaging process.

Also happening for at least these packages:

@turf/[email protected]
@turf/[email protected]
@turf/[email protected]

@rowanwins I'm sorry to disturb but are there any updates on this topic? Whom of the contributors could you suggest to clarify?

Hi @goodwin64

Have you tried one of the v5 releases? Packaging a new release for the v6 series is very complicated and unlikely to happen and there shouldn't be any performance difference rolling back to v5.

None of the current contributors have much experience with typescript sorry

Any luck with these? Ended up importing the whole package myself even though I only need the distance.

Using the latest v5 release worked for me 馃憤

any updates for ^6.0.0?

my workaround with @turf/[email protected].

// turf-distance.d.ts
declare module "@turf/distance" {
  import { Units, Coord } from "@turf/helpers";
  function distance(from: Coord, to: Coord, options: { units?: Units }): number;
  export default distance;
}

Try install @types/turf :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichelBahl picture MichelBahl  路  4Comments

stebogit picture stebogit  路  5Comments

stebogit picture stebogit  路  5Comments

andrewharvey picture andrewharvey  路  3Comments

cglacet picture cglacet  路  4Comments