From 9cca17f21da895e45d04b1618b74ac160910f08c Mon Sep 17 00:00:00 2001 From: Michael Randolph Date: Fri, 21 Aug 2015 17:36:40 -0400 Subject: [PATCH] Fixed fabric so noImplicitAny would stop complaining --- fabricjs/fabricjs-tests.ts | 38 +++++++++++++++--------------- fabricjs/fabricjs.d.ts | 48 +++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/fabricjs/fabricjs-tests.ts b/fabricjs/fabricjs-tests.ts index 89c882b05..5800879f3 100644 --- a/fabricjs/fabricjs-tests.ts +++ b/fabricjs/fabricjs-tests.ts @@ -34,8 +34,8 @@ function sample1() { function sample2() { - var dot, i, - t1, t2, + var dot: fabric.ICircle, i: number, + t1: number, t2: number, startTimer = function() { t1 = new Date().getTime(); return t1; @@ -89,16 +89,16 @@ function sample2() { function sample3() { - var $ = function(id) { return document.getElementById(id) }; + var $: (id: string) => HTMLElement = function(id: string) { return document.getElementById(id) }; - function applyFilter(index, filter) { - var obj = canvas.getActiveObject(); + function applyFilter(index: number, filter: any) { + var obj: fabric.IImage = canvas.getActiveObject(); obj.filters[index] = filter; obj.applyFilters(canvas.renderAll.bind(canvas)); } - function applyFilterValue(index, prop, value) { - var obj = canvas.getActiveObject(); + function applyFilterValue(index: number, prop: string, value: any) { + var obj: fabric.IImage = canvas.getActiveObject(); if (obj.filters[index]) { obj.filters[index][prop] = value; obj.applyFilters(canvas.renderAll.bind(canvas)); @@ -214,7 +214,7 @@ function sample3() { function sample4() { var canvas = new fabric.Canvas('c'); - var $ = function(id) { return document.getElementById(id); }; + var $: (id: string) => HTMLElement = function(id: string) { return document.getElementById(id); }; var rect = new fabric.Rect({ width: 100, @@ -339,10 +339,10 @@ function sample6() { canvas.centerObject(obj); canvas.add(obj); - canvas.add(obj.clone(() => {}).set({ left: 100, top: 100, angle: -15 })); - canvas.add(obj.clone(() => {}).set({ left: 480, top: 100, angle: 15 })); - canvas.add(obj.clone(() => {}).set({ left: 100, top: 400, angle: -15 })); - canvas.add(obj.clone(() => {}).set({ left: 480, top: 400, angle: 15 })); + canvas.add(obj.clone(() => { }).set({ left: 100, top: 100, angle: -15 })); + canvas.add(obj.clone(() => { }).set({ left: 480, top: 100, angle: 15 })); + canvas.add(obj.clone(() => { }).set({ left: 100, top: 400, angle: -15 })); + canvas.add(obj.clone(() => { }).set({ left: 480, top: 400, angle: 15 })); canvas.on('mouse:move', function(options) { var p = canvas.getPointer(options.e); @@ -456,7 +456,7 @@ function sample8() { top = fabric.util.getRandomInt(0 + offset, 500 - offset), angle = fabric.util.getRandomInt(-20, 40), width = fabric.util.getRandomInt(30, 50), - opacity = (function(min, max) { return Math.random() * (max - min) + min; })(0.5, 1); + opacity = (function(min: number, max: number) { return Math.random() * (max - min) + min; })(0.5, 1); switch (className) { @@ -522,7 +522,7 @@ function sample8() { break; case 'shape': - var id = element.id, match; + var id: any = element.id, match: RegExpExecArray; if (match = /\d+$/.exec(id)) { fabric.loadSVGFromURL('../assets/' + match[0] + '.svg', function(objects, options) { var loadedObject = fabric.util.groupSVGElements(objects, options); @@ -586,7 +586,7 @@ function sample8() { } }; - var supportsInputOfType = function(type) { + var supportsInputOfType = function(type: string) { return function() { var el = document.createElement('input'); try { @@ -746,7 +746,7 @@ function sample8() { canvas.on('object:selected', onObjectSelected); canvas.on('group:selected', onObjectSelected); - function onObjectSelected(e) { + function onObjectSelected(e: fabric.IEvent) { var selectedObject = e.target; for (var i = activeObjectButtons.length; i--;) { @@ -1033,7 +1033,7 @@ function sample8() { }; canvas.on('object:selected', function(e: fabric.IEvent) { - slider.value = String((e.target).lineHeight ); + slider.value = String((e.target).lineHeight); }); })(); } @@ -1050,6 +1050,6 @@ function sample8() { function sample9() { var canvas = new fabric.Canvas('c'); - canvas.setBackgroundImage('yolo.jpg',() => { "a" }, { opacity: 45 }); - canvas.setBackgroundImage('yolo.jpg',() => { "a" }); + canvas.setBackgroundImage('yolo.jpg', () => { "a" }, { opacity: 45 }); + canvas.setBackgroundImage('yolo.jpg', () => { "a" }); } diff --git a/fabricjs/fabricjs.d.ts b/fabricjs/fabricjs.d.ts index 503b8c7db..0eb6bacb7 100644 --- a/fabricjs/fabricjs.d.ts +++ b/fabricjs/fabricjs.d.ts @@ -1,6 +1,6 @@ // Type definitions for FabricJS v1.5.0 // Project: http://fabricjs.com/ -// Definitions by: Oliver Klemencic , Joseph Livecchi +// Definitions by: Oliver Klemencic , Joseph Livecchi , Michael Randolph // Definitions: https://github.com/borisyankov/DefinitelyTyped /* tslint:disable:no-unused-variable */ @@ -41,7 +41,7 @@ declare module fabric { * @param {Function} callback * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created. */ - function loadSVGFromString(string: string, callback: (results: IObject[], options: any) => void, reviver?: Function); + function loadSVGFromString(string: string, callback: (results: IObject[], options: any) => void, reviver?: Function): void; /** * Takes url corresponding to an SVG document, and parses it into a set of fabric objects. * Note that SVG is fetched via XMLHttpRequest, so it needs to conform to SOP (Same Origin Policy) @@ -49,14 +49,14 @@ declare module fabric { * @param {Function} callback * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created. */ - function loadSVGFromURL(url: string, callback: (results: IObject[], options: any) => void, reviver?: Function); + function loadSVGFromURL(url: string, callback: (results: IObject[], options: any) => void, reviver?: Function): void; /** * Returns CSS rules for a given SVG document * @param {SVGDocument} doc SVG document to parse */ function getCSSRules(doc: SVGElement): any; - function parseElements(elements: any[], callback: Function, options: any, reviver?: Function); + function parseElements(elements: any[], callback: Function, options: any, reviver?: Function): void; /** * Parses "points" attribute, returning an array of values * @param {String} points points attribute string @@ -99,7 +99,7 @@ declare module fabric { * @param {Function} callback Callback to call when parsing is finished; It's being passed an array of elements (parsed from a document). * @param {Function} [reviver] Method for further parsing of SVG elements, called after each fabric object created. */ - function parseSVGDocument(doc: SVGElement, callback: (results: IObject[], options: any) => void, reviver?: Function); + function parseSVGDocument(doc: SVGElement, callback: (results: IObject[], options: any) => void, reviver?: Function): void; /** * Parses "transform" attribute, returning an array of values * @param {String} attributeValue String containing attribute value @@ -111,11 +111,11 @@ declare module fabric { /** * Wrapper around `console.log` (when available) */ - function log(...values: any[]); + function log(...values: any[]): void; /** * Wrapper around `console.warn` (when available) */ - function warn(...values: any[]); + function warn(...values: any[]): void; //////////////////////////////////////////////////// // Classes @@ -438,7 +438,7 @@ declare module fabric { /** * Sets source of this color (where source is an array representation; ex: [200, 200, 100, 1]) */ - setSource(source: number[]); + setSource(source: number[]): void; /** * Returns color represenation in RGB format ex: rgb(0-255,0-255,0-255) @@ -474,7 +474,7 @@ declare module fabric { * Sets value of alpha channel for this color * @param {Number} alpha Alpha value 0-1 */ - setAlpha(alpha: number); + setAlpha(alpha: number): void; /** * Transforms color to its grayscale representation @@ -627,17 +627,17 @@ declare module fabric { /** * Appends a point to intersection */ - appendPoint(point: IPoint); + appendPoint(point: IPoint): void; /** * Appends points to intersection */ - appendPoints(points: IPoint[]); + appendPoints(points: IPoint[]): void; } interface IIntersectionStatic { /** * Intersection class */ - new (status?: string); + new (status?: string): void; /** * Checks if polygon intersects another polygon */ @@ -1313,7 +1313,7 @@ declare module fabric { /** * Callback; invoked right before object is about to be scaled/rotated */ - onBeforeScaleRotate(target: IObject); + onBeforeScaleRotate(target: IObject): void; // Functions from object straighten mixin // -------------------------------------------------------------------------------------------------------------------------------- @@ -1839,12 +1839,12 @@ declare module fabric { filters: IBaseFilter[]; } interface IImage extends IObject, IImageOptions { - initialize(element?: string|HTMLImageElement, options?: IImageOptions); + initialize(element?: string|HTMLImageElement, options?: IImageOptions): void; /** * Applies filters assigned to this image (from "filters" array) * @param {Function} callback Callback is invoked when all filters have been applied and new image is generated */ - applyFilters(callback: Function); + applyFilters(callback: Function): void; /** * Returns a clone of an instance * @param {Function} callback Callback is invoked with a clone as a first argument @@ -1871,7 +1871,7 @@ declare module fabric { * @return {String} Source of an image */ getSrc(): string; - render(ctx: CanvasRenderingContext2D, noTransform: boolean); + render(ctx: CanvasRenderingContext2D, noTransform: boolean): void; /** * Sets image element for this instance to a specified one. @@ -2539,7 +2539,7 @@ declare module fabric { * Sets object's properties from options * @param {Object} [options] Options object */ - setOptions(options: any); + setOptions(options: any): void; /** * Sets sourcePath of an object * @param {String} value Value to set sourcePath to @@ -2850,7 +2850,7 @@ declare module fabric { } interface IPathGroup extends IObject { - initialize(paths: IPath[], options?: IObjectOptions); + initialize(paths: IPath[], options?: IObjectOptions): void; /** * Returns number representation of object's complexity * @return {Number} complexity @@ -2865,7 +2865,7 @@ declare module fabric { * Renders this group on a specified context * @param {CanvasRenderingContext2D} ctx Context to render this instance on */ - render(ctx: CanvasRenderingContext2D); + render(ctx: CanvasRenderingContext2D): void; /** * Returns dataless object representation of this path group * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output @@ -2993,7 +2993,7 @@ declare module fabric { minY?: number; } interface IPolyline extends IObject, IPolylineOptions { - initialize(points: IPoint[], options?: IPolylineOptions); + initialize(points: IPoint[], options?: IPolylineOptions): void; /** * Returns complexity of an instance * @return {Number} complexity of this instance @@ -3158,7 +3158,7 @@ declare module fabric { * Renders text instance on a specified context * @param {CanvasRenderingContext2D} ctx Context to render on */ - render(ctx: CanvasRenderingContext2D, noTransform: boolean); + render(ctx: CanvasRenderingContext2D, noTransform: boolean): void; /** * Returns object representation of an instance * @param {Array} [propertiesToInclude] Any properties that you might want to additionally include in the output @@ -3347,7 +3347,7 @@ declare module fabric { * Returns true if object has no styling */ isEmptyStyles(): boolean; - render(ctx: CanvasRenderingContext2D, noTransform: boolean); + render(ctx: CanvasRenderingContext2D, noTransform: boolean): void; /** * Returns object representation of an instance * @method toObject @@ -4360,13 +4360,13 @@ declare module fabric { * @param {Object} [properties] Properties shared by all instances of this class * (be careful modifying objects defined here as this would affect all instances) */ - createClass(parent: Function, properties?: any); + createClass(parent: Function, properties?: any): void; /** * Helper for creation of "classes". * @param {Object} [properties] Properties shared by all instances of this class * (be careful modifying objects defined here as this would affect all instances) */ - createClass(properties?: any); + createClass(properties?: any): void; }