When importing Jimp as described in the doc for a TypeScript project:
import Jimp from 'jimp'
I should be able to use Jimp directly as is:
Jimp
.read(fileData)
.then((image: any) => {
...
})
.catch((err: any) => {
...
})
The compile step is OK, but there is runtime error saying:
TypeError: Cannot read property 'read' of undefined
If I use the require-like import syntax:
import * as Jimp from 'jimp'
and use Jimp as below:
Jimp
.read(fileData)
.then((image: any) => {
...
})
.catch((err: any) => {
...
})
I then have a compile error saying:
Property 'read' does not exist on type 'typeof import("/path/to/node_modules/jimp/types/ts3.1/index")'
If I disable manually type checking for Jimp:
// @ts-ignore
Jimp
.read(fileData)
.then((image: any) => {
...
})
.catch((err: any) => {
...
})
There is no runtime error and Jimp works as expected.
To use Jimp with types information, I have to import the types separately and bind them to the classic require syntax:
import Jimp from 'jimp'
// tslint:disable-next-line: no-var-requires
const jimp: Jimp = require('jimp')
And then, use "jimp" instead of "Jimp":
jimp
.read(fileData)
.then((image: any) => {
...
})
.catch((err: any) => {
...
})
Thanks for raising the issue, I'm experiencing the same behaviour unfortunately :( From what I found when researching this, it looks like it is related to this issue https://github.com/oliver-moran/jimp/issues/785
The worst part is that with the require syntax you cant type variables anymore, e.g.
const image: Jimp = await Jimp.read('someFilePath')
will raise an error 😢
I'm also having an error on:
import Jimp from "jimp";
const myBmpBuffer: Buffer = loadDasBuffer();
Jimp.read(myBmpBuffer, (image: any) => {
// something
});
which gives Argument of type 'Buffer' is not assignable to parameter of type 'number'; which basically renders the module quite unusable. Does anyone have a workaround?
@crutchcorn
I sincerely think we should revert the export type to only export using namespace ala 0.6.4 typings. This doesn't mean we'd revert the 3.1 typings. I don't know enough about tsconfig options to provide an alternative.
I have no clue what's happening with @noomly example. I'd have to look further
Same for me.
Types are completely fucked.
Documentation is completely fucked.
Examples from npm doc give problems with strict TS config
With version 0.8.4, @RomainFallet workaround at the top works for me.
With version 0.8.5, the workaround no longer works. Errors given that jimp.read and jimp.AUTO are static members of type Jimp.
Never mind. doesn't work with 0.8.4 either. Does anyone know any kind of workaround to get jimp to work in a typescript project now? I downgraded all the way to 0.5.3 still gives typescript errors.
Even if I lose ability for types...I just need to be able to build the project and run and client is not happy now. Will downgrading to a certain typescript version get this to work? Or what changed that caused the break? thank you
Got this to work again by downgrading...
typescript down to 3.4.5
jimp down to 0.6.4
using import * as Jimp from 'jimp'; to import
I'm taking a look at fixing some of the type issues right now
@noomly it seems the bug you were experiencing was unrelated to the issue described in the OP. However, it's the first PR I've made for ;)
If you can test against 0.8.6-canary.810.481.0 it should include that fix
For everyone else, I have a solution to the overaching issues many users are facing since 0.6.4 in terms of typing problems. I'll have a PR open soon
I will also note to @WeekendMan:
I've been needing a break from working for OSS for a while because I tend to overwork myself. The only times I usually get to work on things is actually shown in your handle: The weekend, man.
Be patient and know that most of us working on OSS do so as a hobbyist project. Because it's open source, you're always able to contribute back upstream if you feel a fix is needed immediately
I had the strange issue that doing the simple import Jimp from 'jimp' was working until I ran my unit tests. I'm think this is due to webpack being able to avoid this problem somehow. However, I would run my unit tests (which are not webpack'd) and I'd get this problem which led me here.
After adding the const jimp: Jimp = require('jimp') hack, everything seemed to be working with my unit tests. However, this then broke the webpack side of things. So I had to create a super hack in the form of const jimp: Jimp = (Jimp || require('jimp')) and it seems to be working in both cases. Yuck!
If someone reverts Corbin changes (i think that’s what was decided on) I
will merge it. I don’t use this project in my work at all so any help
maintaining it is very appreciated
On Wed, Nov 20, 2019 at 12:51 PM Tim Schmidt notifications@github.com
wrote:
I had the strange issue that doing the simple import Jimp from 'jimp' was
working until I ran my unit tests. I'm think this is due to webpack being
able to avoid this problem somehow. However, I would run my unit tests
(which are not webpack'd) and I'd get this problem which led me here.After adding the const jimp: Jimp = require('jimp') hack, everything
seemed to be working with my unit tests. However, this then broke the
webpack side of things. So I had to create a super hack in the form of const
jimp: Jimp = (Jimp || require('jimp')) and it seems to be working in both
cases. Yuck!—
You are receiving this because you commented.Reply to this email directly, view it on GitHub
https://github.com/oliver-moran/jimp/issues/803?email_source=notifications&email_token=AAJDEBCWTUMDDOAAMETAV3TQUWPM3A5CNFSM4JAGSKA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEU2TYI#issuecomment-556378593,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAJDEBA7IGBDQS5B3UWKKZDQUWPM3ANCNFSM4JAGSKAQ
.
@hipstersmoothie I don't think it needs to revert my changes, I think we need to modify the exports or improve the docs with TS usage. The fact that there's more than one working project with #815 and that #810 was quickly and able to be tested to work with one of the reported issues makes me believe that the changes I'd made as-of-now are no worse than the 0.6.5 release with the issues in them and significantly improved due to testing and more accurate overall tests
I've done the closest thing to "reverting" the changes from 0.6.5 that are causing many of the problems that people are reporting (and why so many are saying that 0.6.4 were the last working version for them):
https://github.com/oliver-moran/jimp/pull/820
(I would ask folks to test the version of jimp associated with this PR but just my luck the release step failed)
We also need to bring in the PR:
https://github.com/oliver-moran/jimp/pull/815
In order to fix the runtime errors that were caused unrelated to the TS definition changes in 0.8
So when testing the version above, if you notice runtime errors, that is fixed in a different PR
Lastly, @noomly's issues with the 0.8.5 defintion files (that _were_ a regression from 0.8 from other versions) have been fixed in a PR for a while that just needs to be merged:
Are y'all able to test against 0.9.2 stable release. There was some work done to improve TS stability and should fix _everyone's_ issues with typings (if you were one of the ones that had to revert to 0.6.4, this includes you). Please test against and confirm/deny crosses fingers
:raised_hand_with_fingers_splayed: @crutchcorn I'm really good at writing typings, are you open to a large PoC PR on this?
Hi @forivall 👋 Small world!
What'd the PoC PR be in regards to? I've done a fair amount of work in order to modularize the typings for plugins and it seems to be in a fairly stable place now especially with the type tests that were written
To be clear, I'm not against it by any means - just wanted to check what I might've missed mentally beforehand :)
Speaking of... @hipstersmoothie, think we can close this issue out? I didn't realize it was still open and according to many users, it seems we're finally at a stable place
Closed! Good job by the way. Now that the storm has settled it seems like all is good.
I was originally thinking of something along the lines of how the express typings in DefinitelyTyped does plugins, but then, by playing around in my node modules, I found a satisfactory solution: https://github.com/oliver-moran/jimp/compare/master...forivall:fix/split-ctor-instance-types
wait, nvm, i've still got more tweaks to do.
Oh gotcha I see what you're up to! Love what you've been able to do thus far. If we're able to get some stuff into our type tests, I'd appreciate that as well! I think once you have more tweaks (as you'd mentioned, I didn't have any notes at a first glance), I'll be able to review the PR today and we can probably get it moved forward.
Thanks so much for jumping in and helping! :D
:rocket: Issue was released in v0.10.0 :rocket:
:rocket: Issue was released in v0.10.0 :rocket:
Most helpful comment
Are y'all able to test against
0.9.2stable release. There was some work done to improve TS stability and should fix _everyone's_ issues with typings (if you were one of the ones that had to revert to 0.6.4, this includes you). Please test against and confirm/deny crosses fingers