-
Notifications
You must be signed in to change notification settings - Fork 323
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
Typescript: Incorrect usage of Union Typing (mostly options) #539
Comments
Hi @CodeMan99 - thanks for reporting this! |
Correct. This is not a show stopper. Just would be a very nice to have for better type support. |
No worries @CodeMan99 - we will update this thread when there are updates on our side. |
I was about to create a new issue, then I found this thread and thought: well, mine is kinda relevant to this one, so let's do it here. According to the doc, the function upload(file: string | buffer, options?: UploadApiOptions, callback?: UploadResponseCallback): Promise<UploadApiResponse>; Think about that. I'm willing to send a PR if needed. Update:const image = new Buffer(...); // contains buffer of a real image
cloudinary.v2.uploader.upload(image.toString()) yields |
Hi @CodeMan99 - An update on the original query - after speaking with our team they advised that because we're using Hi @msrumon - Thanks for reporting this. Definitely, feel free to submit a PR and we can ask our team to review it. You can also use the
|
Yes, I ended up using import { parse } from 'path'
import { Readable } from 'stream'
import { UploadApiOptions, v2 as cloudinary } from 'cloudinary'
// other imports //
export class CloudinaryDriver implements CloudinaryDriverContract {
// other implementations //
public async put(location: string, contents: string | Buffer, options?: WriteOptions) {
try {
const path = parse(location)
const upOptions: UploadApiOptions = {
public_id: options && 'name' in options ? parse(options.name).name : path.name,
folder: path.dir || undefined,
unique_filename: false,
}
if (Buffer.isBuffer(contents)) {
await new Promise((resolve, reject) => {
const stream = cloudinary.uploader.upload_stream(upOptions, (err, res) => {
if (err) {
reject(err)
} else {
resolve(res)
}
})
Readable.from(contents).pipe(stream)
})
} else {
await cloudinary.uploader.upload(contents, upOptions)
}
} catch (error) {
throw new CannotWriteFileException(error)
}
}
} However, I'll play around with the |
Sounds good @msrumon - let us know how it goes. If you convert the Buffer to a Typedarray then upload() should be able to accept that. Otherwise, if you don't have the file stored locally on the filesystem and you're only getting a stream then upload_stream() is the way to go. |
Describe the bug in a sentence or two.
Many options type arguments are using union when the intention is an intersection.
Issue Type (Can be multiple)
Steps to reproduce
An example using the
ConfigAndUrlOptions
type.This example will not fail to compile. However,
force_version
is provided as a string.Correct Usage
Instead of a union, the
ConfigAndUrlOptions
object should be an intersection.Wrap Up
There are a lot of unions being mis-used this way. I'm happy to help create a PR. However, doing so would take significant time for me.
The text was updated successfully, but these errors were encountered: