Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jimp.write(path) has weird typescript type ${string}.${Extension} #1349

Open
ma-zal opened this issue Oct 10, 2024 · 1 comment
Open

Jimp.write(path) has weird typescript type ${string}.${Extension} #1349

ma-zal opened this issue Oct 10, 2024 · 1 comment

Comments

@ma-zal
Copy link

ma-zal commented Oct 10, 2024

Expected Behavior

I expect standard string as datatype of path input parameter of Jimp.write function.

Current Behavior

Used complicated (and on many places incompatible) data type${string}.${Extension} for input parameter path.

Need to explicitly retype by ugly as '${string}.${string}'

Failure Information (for bugs)

N/A

Steps to Reproduce

const icon = await Jimp.read(sourceImgPath);
const writePath = path.join(__dirname, 'myfile.png');
await icon.write(writePath); // Error: Argument of type 'string' is not assignable to parameter of type '`${string}.${string}`'.ts(2345)

Screenshots

N/A

Context

  • Jimp Version: 1.6.0
  • Operating System: MaOS
  • Node version: 20.x

Failure Logs

Error: Argument of type 'string' is not assignable to parameter of type '`${string}.${string}`'.ts(2345)
@frederik-b
Copy link

I think this is even bigger...
I want to resize a temporary file inplace with a filename like: /tmp/67f63be03de2e62bccbab3400
However something like

img.resize({w: smallestLength}).write(path as `${string}.${string}`)

==>
Fatal: no ErrorError: Unsupported MIME type: null
at Jimp.getBuffer (/usr/local/opt/backend/node_modules/@jimp/core/src/index.ts:426:15)
at Jimp.write (/usr/local/opt/backend/node_modules/@jimp/core/src/index.ts:503:20)
at resizeImage (/usr/local/opt/backend/src/lib/resizeImage.ts:16:44)

does not work as the actual implementation

async write(path, options) {
   const mimeType = mime.getType(path);
   await writeFile(path, await this.getBuffer(mimeType, options));
}

really really needs it to be

`${string}.${string}`

I probably should be possible to set the mimeType by the options and only infer the type by path when not explicitly setting the option.

Workaround:

await writeFile(
      path,
      await img.resize({h: smallestLength}).getBuffer(img.mime as typeof JimpMime[keyof typeof JimpMime])
    )

here again you can't pass just any string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants