Pomax / bezierjs

A nodejs and client-side library for (cubic) Bezier curve work
MIT License
1.75k stars 235 forks source link

Typescript support #65

Open Izhaki opened 7 years ago

Izhaki commented 7 years ago

Having spent futile 4 hours trying to use this library in a typescript code base (ES6 module imports), I wonder if anyone has managed, and show how.

Seems like @danmarshall did some work on this, but none seem to work.

There's this typescript fork/port, which I couldn't install at all - it just throws errors when you run npm install; it is also at 2.1.0 at the moment.

Then, there's the typings definitions, and an npm package for @types/bezier-js, but the devil will take me I only get compilation/run-time errors with these.

Anyone?

danmarshall commented 7 years ago

Yes I've ported it to TypeScript, what version are you using?

Izhaki commented 7 years ago

2.0.3

  "devDependencies": {
    "@angular/core": "^2.0.1",
    "@types/bezier-js": "0.0.5",
    "@types/es6-shim": "^0.31.32",
    "@types/jasmine": "^2.5.35",
    "bezier-js": "^2.2.1",
    "browserify": "^13.0.1",
    "chokidar-cli": "^1.2.0",
    "figlet-cli": "^0.1.0",
    "http-server": "^0.9.0",
    "istanbul": "^1.1.0-alpha.1",
    "jasmine": "^2.4.1",
    "jasmine-fail-fast": "^2.0.0",
    "jsdom": "^9.4.1",
    "npm-run-all": "^3.1.0",
    "rxjs": "^5.0.0-beta.12",
    "ts-node": "^1.4.3",
    "tsify": "^2.0.2",
    "typescript": "^2.0.3",
    "uglify-js": "^2.7.0",
    "zone.js": "^0.6.25"
  },

Then:

import { Bezier } from 'bezier-js';
danmarshall commented 7 years ago

I'll have to look in to how @types works for v1.8 / v2.0. I'm not sure why it wouldn't be backward compatible.

danmarshall commented 7 years ago

I just did an npm install on a fresh clone, no errors. What are the errors you see on npm install ?

Izhaki commented 7 years ago
npm install danmarshall/bezierjs --save-dev

Throws:

npm ERR! git rev-list -n1 master: fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
npm ERR! git rev-list -n1 master: Use '--' to separate paths from revisions, like this:
npm ERR! git rev-list -n1 master: 'git <command> [<revision>...] -- [<file>...]'
npm ERR! git rev-list -n1 master: 
npm ERR! git rev-list -n1 master: fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
npm ERR! git rev-list -n1 master: Use '--' to separate paths from revisions, like this:
npm ERR! git rev-list -n1 master: 'git <command> [<revision>...] -- [<file>...]'
npm ERR! git rev-list -n1 master: 
npm ERR! git rev-list -n1 master: fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
npm ERR! git rev-list -n1 master: Use '--' to separate paths from revisions, like this:
npm ERR! git rev-list -n1 master: 'git <command> [<revision>...] -- [<file>...]'
npm ERR! git rev-list -n1 master: 
npm ERR! Darwin 14.5.0
npm ERR! argv "/Users/izhaki/.nvm/versions/node/v4.4.7/bin/node" "/Users/izhaki/.nvm/versions/node/v4.4.7/bin/npm" "install" "danmarshall/bezierjs" "--save-dev"
npm ERR! node v4.4.7
npm ERR! npm  v3.10.3
npm ERR! code 128

npm ERR! Command failed: git rev-list -n1 master
npm ERR! fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
npm ERR! Use '--' to separate paths from revisions, like this:
npm ERR! 'git <command> [<revision>...] -- [<file>...]'
npm ERR! 
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Volumes/Data/Cloud/CloudStation/Development/gefri/npm-debug.log
danmarshall commented 7 years ago

Can you just npm install bezier-js --save and then just use the d.ts file ?

Izhaki commented 7 years ago

Tried that (with https://github.com/danmarshall/bezierjs/blob/gh-pages/bezier.d.ts), but it exports BezierJs and I import 'bezier-js' so I get compilation error 'module not found'

Izhaki commented 7 years ago

When I import using

import { Bezier } from 'bezier-js';

That line compiles (and VS Code hints the right definition):

new Bezier( 0, 0, 0, 0, 0, 0 )

So the @types/bezier-js seems to be sound.

It's just that at runtime I get complains:

TypeError: bezier_js_1.Bezier is not a function

If I console.log(Bezier) I get undefined.

If I import using import * as Bezier from 'bezier-js', then console.log( Bezier ) I get:

{ [Function]
  fromSVG: [Function],
  quadraticFromPoints: [Function],
  cubicFromPoints: [Function],
  getUtils: [Function] }

Which seems to be the definition of class Bezier (with its static functions).

But then if I try

new Bezier( ... )

I get:

Cannot use 'new' with an expression whose type lacks a call or construct signature.
danmarshall commented 7 years ago

How about import { BezierJs } from 'bezier-js';

Izhaki commented 7 years ago
Module '"bezier-js"' has no exported member 'BezierJs'.

I can push the non-working code for you to play with.

danmarshall commented 7 years ago

Also are you "packaging" the Node version of bezier-js or are you using a Githubissues.

  • Githubissues is a development platform for aggregating issues.