Last active
October 5, 2018 03:23
-
-
Save chiepomme/11218265 to your computer and use it in GitHub Desktop.
typescript declaration for two.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare class Two { | |
type: Two.Types; | |
width: number; | |
height: number; | |
constructor(params?: TwoConstructionParams); | |
appendTo(element: HTMLElement); | |
makeLine(x1: number, y1: number, x2: number, y2: number): Two.Shape; | |
makeRectangle(x: number, y: number, width: number, height: number): Two.Shape; | |
makeCircle(x: number, y: number, radius: number): Two.Shape; | |
makeEllipse(x: number, y: number, width: number, height: number): Two.Shape; | |
makeCurve(x1: number, y1: number, open: boolean): Two.Shape; | |
makeCurve(x1: number, y1: number, x2: number, y2: number, open: boolean): Two.Shape; | |
makeCurve(x1: number, y1: number, x2: number, y2: number, x3: number, y3: number, open: boolean): Two.Shape; | |
makePolygon(x1: number, y1: number, x2: number, y2: number, open: boolean): Two.Polygon; | |
makeGroup(objects: Array<any>): Two.Group; | |
bind(event: Two.Events, callback: (arg?: Array<any>) => void): Two; | |
unbind(event: Two.Events, callback: (arg?: Array<any>) => void): Two; | |
play(); | |
pause(); | |
update(); | |
render(); | |
add(); | |
remove(); | |
clear(); | |
} | |
declare module Two { | |
enum Types { | |
webgl, | |
svg, | |
canvas, | |
} | |
enum Events { | |
play, | |
pause, | |
update, | |
render, | |
resize, | |
change, | |
remove, | |
insert, | |
} | |
class Vector { | |
x: number; | |
y: number; | |
set(x: number, y: number); | |
} | |
class LogicalShape extends Backbone.Events { | |
translation: Two.Vector; | |
rotation: number; // radian | |
scale: number; | |
visible: boolean; | |
parent: Two.Group; | |
vertices: Collection; | |
} | |
export class Shape extends LogicalShape { | |
parent: Two.Group; | |
stroke: string; // color | |
fill: string; // color | |
linewidth: number; | |
opacity: number; // 0-1 | |
/** http://www.w3.org/TR/SVG/images/painting/linecap.svg */ | |
cap: string; | |
/** http://www.w3.org/TR/SVG/images/painting/linejoin.svg */ | |
join: string; | |
miter: number; | |
noStroke(); | |
noFill(); | |
subdivide(); | |
} | |
class Polygon extends Shape { | |
vertices: Collection; | |
} | |
class Group extends LogicalShape { | |
children: Array<any> | |
} | |
interface Collection extends Array<any> { } | |
} | |
interface TwoConstructionParams { | |
type?: Two.Types; | |
width?: number; | |
height?: number; | |
autostart?: boolean; | |
fullscreen?: boolean; | |
} |
The easiest way to get past this is to simply remove extends Backbone.Events
from the type specified for the shape class on line 58. Shape /does/ extend Backbone.Events, but it isn't necessary to capture this in the typings if you don't actually use backbone events for shapes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I am trying to use this file, and Typescript is complaining about the variable Backbone as unknown, any ideas what would cause this error?