question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typings for @turf/distance

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
AntonPilyakcommented, May 29, 2019

any updates for ^6.0.0?

4reactions
Nkzncommented, Sep 9, 2019

my workaround with @turf/distance@6.0.1.

// 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;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

@turf/distance - npm
Calculates the distance between two points in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global ...
Read more >
Advanced geospatial analysis - Turf.js
Calculates the distance between two points in degrees, radians, miles, or kilometers. This uses the Haversine formula to account for global curvature. Arguments ......
Read more >
The Wonder of Turf.js | Codementor
Easily find distance between two points. This takes into account the curvature of the earth, which is crucial in long-distance geographic ...
Read more >
@turf/point-to-line-distance | Yarn - Package Manager
CDNs. unpkg: unpkg.com/@turf/point-to-line-distance/. jsDelivr · Popularity. GitHub stargazers: 0 · Activity. Commits last 3 months: 13 · Usage. Dependencies @turf ...
Read more >
Turf - Best of JS
Turf · +105 · +72 · +62 · +76 · +89 · +66 · +116 · +80.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found