Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript definitions #515

Closed
50 tasks done
DenisCarriere opened this issue Nov 9, 2016 · 15 comments
Closed
50 tasks done

Typescript definitions #515

DenisCarriere opened this issue Nov 9, 2016 · 15 comments

Comments

@DenisCarriere
Copy link
Member

DenisCarriere commented Nov 9, 2016

Problem

At the moment you can install Typescript 2.0 definitions via npm install @types/turf.

However, not all of the definitions are defined and it can be overwhelming trying to manage a 1280+ LOC type definition.

Solution

I'm suggesting we host the Typescript type definitions within the Turf library instead of DefinitelyTyped.

By including a simple & minimalistic index.d.ts and test/types.ts within each package, the type definitions will be bundled with each namespace package.

By default index.d.ts will be automatically detected, however including "types": "index.d.ts" in the package.json is a good practice.

/// <reference types="geojson" />

/***
 * http://turfjs.org/docs/#point
 */
export type Point = Array<number>
export function point(coordinates: Point, properties?: Object): GeoJSON.Feature<GeoJSON.Point>;

To-Do

  • turf-along
  • turf-area
  • turf-bbox
  • turf-bbox-polygon
  • turf-bearing
  • turf-bezier
  • turf-buffer
  • turf-center
  • turf-center-of-mass
  • turf-centroid
  • turf-circle
  • turf-collect
  • turf-combine
  • turf-concave
  • turf-convex
  • turf-destination
  • turf-difference
  • turf-distance
  • turf-envelope
  • turf-explode
  • turf-flip
  • turf-helpers
  • turf-hex-grid
  • turf-idw
  • turf-inside
  • turf-intersect
  • turf-invariant
  • turf-isolines
  • turf-kinks
  • turf-line-distance
  • turf-line-slice
  • turf-line-slice-along
  • turf-meta
  • turf-midpoint
  • turf-nearest
  • turf-planepoint
  • turf-point-grid
  • turf-point-on-line
  • turf-point-on-surface
  • turf-random
  • turf-sample
  • turf-simplify
  • turf-square
  • turf-square-grid
  • turf-tag
  • turf-tesselate
  • turf-tin
  • turf-triangle-grid
  • turf-union
  • turf-within
DenisCarriere added a commit that referenced this issue Nov 9, 2016
DenisCarriere added a commit that referenced this issue Nov 9, 2016
@DenisCarriere
Copy link
Member Author

DenisCarriere commented Nov 22, 2016

@tmcw @morganherlocker Good news! With the latest update 3.6.1 the typescript definitions are working for @turf/helpers without any additional custom Typescript installs.

After this is done... Implementing this for Flow should be easy enough since both of them have a very similar syntax, only need to add a index.js.flow or add the flow syntax directly in the source code.

image

{
  "name": "test",
  "main": "index.js",
  "dependencies": {
    "@turf/helpers": "^3.6.1"
  }
}

@DenisCarriere
Copy link
Member Author

🚀🚀 Woot! Completed all the Typescript definitions

packages/turf-along/index.d.ts
packages/turf-area/index.d.ts
packages/turf-bbox-polygon/index.d.ts
packages/turf-bbox/index.d.ts
packages/turf-bearing/index.d.ts
packages/turf-bezier/index.d.ts
packages/turf-buffer/index.d.ts
packages/turf-center-of-mass/index.d.ts
packages/turf-center/index.d.ts
packages/turf-centroid/index.d.ts
packages/turf-circle/index.d.ts
packages/turf-collect/index.d.ts
packages/turf-combine/index.d.ts
packages/turf-concave/index.d.ts
packages/turf-convex/index.d.ts
packages/turf-destination/index.d.ts
packages/turf-difference/index.d.ts
packages/turf-distance/index.d.ts
packages/turf-envelope/index.d.ts
packages/turf-explode/index.d.ts
packages/turf-flip/index.d.ts
packages/turf-helpers/index.d.ts
packages/turf-hex-grid/index.d.ts
packages/turf-idw/index.d.ts
packages/turf-inside/index.d.ts
packages/turf-intersect/index.d.ts
packages/turf-invariant/index.d.ts
packages/turf-isolines/index.d.ts
packages/turf-kinks/index.d.ts
packages/turf-line-distance/index.d.ts
packages/turf-line-slice-along/index.d.ts
packages/turf-line-slice/index.d.ts
packages/turf-meta/index.d.ts
packages/turf-midpoint/index.d.ts
packages/turf-nearest/index.d.ts
packages/turf-planepoint/index.d.ts
packages/turf-point-grid/index.d.ts
packages/turf-point-on-line/index.d.ts
packages/turf-point-on-surface/index.d.ts
packages/turf-random/index.d.ts
packages/turf-sample/index.d.ts
packages/turf-simplify/index.d.ts
packages/turf-square-grid/index.d.ts
packages/turf-square/index.d.ts
packages/turf-tag/index.d.ts
packages/turf-tesselate/index.d.ts
packages/turf-tin/index.d.ts
packages/turf-triangle-grid/index.d.ts
packages/turf-union/index.d.ts
packages/turf-within/index.d.ts

@morganherlocker
Copy link
Member

Nice work!

@DenisCarriere
Copy link
Member Author

Thanks! Should be good to publish to npm, test it out before, but so far the typescript definitions are working in my environment.

@DenisCarriere
Copy link
Member Author

DenisCarriere commented Nov 30, 2016

@morganherlocker @tmcw Just published a new version to npm 3.6.3 with all of these changes.

One minor hiccup is I forgot to include "types": "index.d.ts" in the package.json, I thought it was optional, without it it doesn't detect the Typescript definition file.

I hope you don't mind me pushing another release in the same day to 3.7.0 (Since Typescript definitions is a new feature, I'll bump to a minor release). I'll do the appropriate changes to the package.json's and publish another release.

@nicolasca
Copy link

nicolasca commented Jul 3, 2018

Hey,

I don't see anymore index.d.ts for the centroid package. Is this a missing ?

Thanks

@geirsagberg
Copy link
Contributor

Seems to be missing for @turf/distance as well.

@wafisher
Copy link
Contributor

How are we supposed to use types? I have the following, but WebStorm/IntelliJ doesn't automatically see these types (why?) so I wonder if I'm doing something wrong.

# MyFile.tsx
import * as turf from '@turf/turf'
import { Point, Feature, Properties } from '@turf/turf'

export function simpleFn(lat: number, long: number, properties: Properties): Feature<Point> {
    return turf.point([long, lat], properties)
}

@sgarwood
Copy link

How are we supposed to use types? I have the following, but WebStorm/IntelliJ doesn't automatically see these types (why?) so I wonder if I'm doing something wrong.

# MyFile.tsx
import * as turf from '@turf/turf'
import { Point, Feature, Properties } from '@turf/turf'

export function simpleFn(lat: number, long: number, properties: Properties): Feature<Point> {
    return turf.point([long, lat], properties)
}

Try removing @types/turf if you have it in your package.json file if you have it

@bockoblur
Copy link

I don't see anymore index.d.ts for the centroid package. Is this a missing ?

Any news on this? Just installed @turf/centroid 6.0.1 and types are missing…

@onsah
Copy link

onsah commented Nov 20, 2020

It is also missing from @turf/center-of-mass package

@gyula-s
Copy link

gyula-s commented Dec 15, 2020

I don't see anymore index.d.ts for the centroid package. Is this a missing ?

Any news on this? Just installed @turf/centroid 6.0.1 and types are missing…

I came around this, by importing this:

import centroid from "@turf/centroid";
import * as turf from "@turf/helpers";
import { Feature, Point } from "@turf/helpers";

and then use it with

let center: Feature<Point> = centroid(pol);

@mfedderly
Copy link
Collaborator

If you use 6.2.0-alpha.3 the types and versions are all consistent. I'm working on getting 6.2.0 stable but its definitely worth checking out if you want tree shaking, consistent package dependencies, and typescript definitions.

@gyula-s
Copy link

gyula-s commented Dec 15, 2020

If you use 6.2.0-alpha.3 the types and versions are all consistent. I'm working on getting 6.2.0 stable but its definitely worth checking out if you want tree shaking, consistent package dependencies, and typescript definitions.

ok. thanks. Do you have a rough estimate on a stable release ETA?

@mfedderly
Copy link
Collaborator

I'm hoping to maybe get it done by end of year but the timeline is not completely set. 6.2.0-alpha.3 should be usable if you give it a try and test it a little bit. I have been using -alpha2 successfully for a few months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants