-
-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
TypeScript: Jimp types are not corresponding to Jimp implementation #803
Comments
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 #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 |
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. |
With version 0.8.4, @RomainFallet workaround at the top works for me. |
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. |
Got this to work again by downgrading... |
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 For everyone else, I have a solution to the overaching issues many users are facing since |
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 After adding the |
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 ***@***.***> 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
<#803>,
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): (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: 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 |
🖐️ @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: 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 |
* Properly split constructor and instance types Fixes #803 * Fix a preexisting typo in Well Formed Plugin detection * Also declare encoders and decoders types * Update types tests * Fix custom instance types * Fix tsTest errors * Fix typings for typescript 3.1
🚀 Issue was released in |
🚀 Issue was released in |
Still having this issue, you could use the require statement to fix it but it's bad practice, no other library has this issue To fix the "read is not defined" error you can do this
|
"no other library has this problem" lol ok. PRs welcome, I'll review them myself :) |
|
For the record, I've just encountered this behaviour when updating So it's not the way documentation suggests. |
Good catch. just pushed an update to the docs |
Expected Behavior
When importing Jimp as described in the doc for a TypeScript project:
I should be able to use Jimp directly as is:
Current Behavior
The compile step is OK, but there is runtime error saying:
If I use the require-like import syntax:
and use Jimp as below:
I then have a compile error saying:
If I disable manually type checking for Jimp:
There is no runtime error and Jimp works as expected.
Failure Information (for bugs)
Context
Workaround
To use Jimp with types information, I have to import the types separately and bind them to the classic require syntax:
And then, use "jimp" instead of "Jimp":
The text was updated successfully, but these errors were encountered: