I am using [email protected]. In this package the openUploadStreamWithId in the GridFSBucket is defined as ObjectId.
mongodb.d.ts
export declare class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
...
openUploadStreamWithId(id: ObjectId, filename: string, options?: GridFSBucketWriteStreamOptions): GridFSBucketWriteStream;
...
}
But it should be type GridFSBucketWriteStreamId = string | number | Object | ObjectID; stackexchange mongodb driver
I'm using a string as id, instead of an ObjectId, therefore I have to fix the definition.
How can I extend the openUploadStreamWithId typescript?
CodePudding user response:
First of all, why don't you just create an ObjectID from your string?
Anyway, let's say you have this
const myStringID = '5783878927082'
Instead of messing with the types, just do the good ol' unknown trick:
openUploadStreamWithId(myStringID as unknown as ObjectID, ...)
This will stop the compiler complaining, but you better know what you're doing.
