Skip to content

[1.3.0 / 1.3.1] TypeScript Cropper.options dragMode breaks at runtime #308

Closed
@peterpeterparker

Description

@peterpeterparker

I'm submitting a...

[X ] Bug report

Current behavior

With the introduction of typescript in 1.3.0, the Cropper.options dragMode is now defined as a type DragMode. Unfortunately, setting it to the constant value (see code below) will then fail at runtime with following error:

console.js:35 ERROR TypeError: Cannot read property 'Move' of undefined

Expected behavior

No error. A possible solution is maybe to set dragMode as string?

export interface Options {
    ...
    dragMode?: string; // instead of DragMode
    ...
 }

Minimal reproduction of the problem with instructions

 import Cropper from 'cropperjs';
 
 this.cropper = new Cropper(myUrl, {
        viewMode: 2,
        aspectRatio: 1,
        dragMode: Cropper.DragMode.Move, // <-- Here the problem. Enum is not converted and will fail at runtime
        modal: true,
        guides: false,
        highlight: true,
        background: true,
        autoCrop: true,
        autoCropArea: 0.9,
        responsive: true,
        ready: (event: CustomEvent) => {
        }
 });

Environment

Cropper.js version: 1.3.1

Workaround

Right now, I have then declared dragMode like following to bypass the problem

import Cropper from 'cropperjs';
 
 this.cropper = new Cropper(myUrl, {
        ...
        dragMode: <any> 'move',
        ...
        ready: (event: CustomEvent) => {
        }
 });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions