Skip to content

Commit 84a1e6c

Browse files
committed
feat(File): clone accepts overrides arg to override any properties
1 parent a30c829 commit 84a1e6c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/data/file.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,18 @@ export class File implements FileLike {
197197
* Creates a clone of the file with a new `documentObj`. This is the
198198
* recommended way of duplicating files, as it will prevent them both
199199
* referencing the same documentObj.
200+
* @param overrides Override any of the `FileDetails` that initialize `File`.
201+
* Note that `fileObj` will be overridden by the `documentObj` in overrides,
202+
* or cloned from this file.
200203
*/
201-
clone() {
204+
clone(overrides?: Partial<FileDetails>) {
205+
const { documentObj, ...rest } = overrides || {};
202206
return new File({
203207
name: this.name,
204208
originalName: this.originalName,
205209
extension: this.extension,
206-
documentObj: blobToDocument(documentToBlob(this.documentObj.get()), this.extension),
210+
...rest,
211+
documentObj: documentObj || blobToDocument(documentToBlob(this.documentObj.get()), this.extension),
207212
});
208213
}
209214

0 commit comments

Comments
 (0)