question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"All crop params are initially optional." When infact they are not

See original GitHub issue

github_iconTop GitHub Comments

3reactions
nzayatz14commented, Sep 24, 2021

@DominicTobias making the prop crop a Partial <Crop> object as a parameter fixes the issue of having to pass a full Crop into the component, but it does not fix the issue of declaring a local value as a Crop.

For example, your current definition of a Crop is

export interface Crop {
  aspect?: number;
  x: number;
  y: number;
  width: number;
  height: number;
  unit: 'px' | '%';
}

so, if I wanted to create a local state variable to store the current crop in my component, it may look something like

const [myCrop, setMyCrop] = useState<Crop>({ unit: '%', width: 50, aspect: 1 }); //this throws a type error

This particular line, however, would throw a TypeError because my initial state value of { unit: '%', width: 50, aspect: 1 } is missing the parameters height, x, and y.

I believe removing the Partial<> from the propType and changing the type definition of Crop to be:

export interface Crop {
  aspect?: number;
  x?: number;
  y?: number;
  width?: number;
  height?: number;
  unit?: 'px' | '%';
}

may just work, though I do not know if you need any of those fields to be required specifically.

Hope this sheds some light on the issue.

0reactions
DominicTobiascommented, Mar 2, 2022

This has changed in v10 (along with many breaking changes) and is no longer an issue as a complete crop always has to be passed in. Check the release notes for more info.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Select box not visible · Issue #149 · DominicTobias/react ...
All crop params are optional. However while you can initially omit the crop object, any subsequent change will need to be saved to...
Read more >
Provide option to apply default crop if user doesn't select any
A client had requested a change where they wanted all the default crops to be automatically generated after uploading a file (rather than ......
Read more >
optional parameters for immutable classes - Stack Overflow
crops up frequently in creating immutable classes that have some ... The firstName is not provided as named parameter, it's optional.
Read more >
Cutting and Bordering -- IM v6 Examples - ImageMagick
The " -crop " image operator will simply cut out the part of all the images in the current sequence at the size...
Read more >
Code documentation - The Python Crop Simulation Environment
One or more of these sections may be excluded when they are not appropriate for the SimulationObject that is described. The table specifying...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found