From 932727f5785b3bdab808da5852467358dc09d588 Mon Sep 17 00:00:00 2001 From: Don Denton Date: Tue, 17 Apr 2018 20:12:42 -0500 Subject: [PATCH] Use partials for setting methods which take options (#24959) This commit addresses a problem where the following would produce a type error, even though it was valid code: ```typescript setCanvasData({left: 23}) ``` I have changed the argument type for all of the `setXXX` methods which accept an object as their argument. In the spec files for cropperjs, @fengyuanchen uses these objects as partials for setters. So I have made the type definitions follow that same pattern. I changed the `cropperjs.CropBoxData` type to act the same way as well. It looks like it was changed at some point, I am guessing to allow it to be used as a partial in the `setCropBoxData` method. Since, like all the other data structures here, it contains all members when you `get` it, I have made all members required parts of the object and changed the setter method to accept a partial. I hope this all makes sense. Basically, I went from the first line below to the second. ```typescript setXXXXX(thing: cropperjs.SomeInterface): void setXXXXX(thing: Partial): void ``` Then I changed `cropperjs.CropBoxData` to fit this new system. --- types/cropperjs/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/cropperjs/index.d.ts b/types/cropperjs/index.d.ts index 60b508dd8f..30556e11fc 100644 --- a/types/cropperjs/index.d.ts +++ b/types/cropperjs/index.d.ts @@ -312,19 +312,19 @@ declare namespace cropperjs { /** * the offset left of the crop box */ - left?: number; + left: number; /** * the offset top of the crop box */ - top?: number; + top: number; /** * the width of the crop box */ - width?: number; + width: number; /** * the height of the crop box */ - height?: number; + height: number; } interface CanvasData { /** @@ -516,7 +516,7 @@ declare class cropperjs { /** * Change the cropped area position and size with new data (base on the original image). */ - setData(data: cropperjs.Data): void; + setData(data: Partial): void; /** * Output the container size data. @@ -545,7 +545,7 @@ declare class cropperjs { /** * Change the canvas (image wrapper) position and size with new data. */ - setCanvasData(data: cropperjs.CanvasData): void; + setCanvasData(data: Partial): void; /** * Output the crop box position and size data. @@ -555,7 +555,7 @@ declare class cropperjs { /** * Change the crop box position and size with new data. */ - setCropBoxData(data: cropperjs.CropBoxData): void; + setCropBoxData(data: Partial): void; /** * Get a canvas drawn the cropped image.