Skip to content

Commit da89ad3

Browse files
yusuke-omaesegayuu
andauthored
🤖 Merge PR DefinitelyTyped#65344 [@wordpress/editor] fix type function uploadMedia() by @yusuke-omae
Co-authored-by: segayuu <[email protected]>
1 parent 596daba commit da89ad3

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

types/wordpress__editor/utils/index.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
export { uploadMedia as mediaUpload } from '@wordpress/media-utils';
1+
import type { UploadMediaOptions } from '@wordpress/media-utils';
2+
3+
export type MediaUploadOptions = Omit<UploadMediaOptions, 'maxUploadFileSize' | 'onError' | 'wpAllowedMimeTypes'> &
4+
Partial<Pick<UploadMediaOptions, 'maxUploadFileSize'>> & {
5+
onError?(message: string): void;
6+
};
7+
8+
export function mediaUpload(options: MediaUploadOptions): void;
29

310
/**
411
* Performs some basic cleanup of a string for use as a post slug

types/wordpress__editor/wordpress__editor-tests.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { dispatch, select } from '@wordpress/data';
22
import * as e from '@wordpress/editor';
33

44
declare const BLOCK_INSTANCE: import('@wordpress/blocks').BlockInstance;
5+
declare const FILELIST: FileList;
6+
declare const FILE_ARRAY: File[];
57

68
// $ExpectType EditorStoreDescriptor
79
e.store;
@@ -404,3 +406,32 @@ select('core/editor').getPostEdits().foo;
404406

405407
// $ExpectType boolean
406408
select('core/editor').inSomeHistory(state => state.foo === true);
409+
410+
//
411+
// Utils
412+
// ============================================================================
413+
414+
// $ExpectType void
415+
e.mediaUpload({
416+
filesList: FILELIST,
417+
onFileChange(files) {
418+
console.log(files[0].alt, files[0].media_type);
419+
},
420+
});
421+
422+
// $ExpectType void
423+
e.mediaUpload({
424+
additionalData: {
425+
foo: 'foo',
426+
bar: ['bar', 'baz'],
427+
},
428+
allowedTypes: ['image/jpeg'],
429+
filesList: FILE_ARRAY,
430+
maxUploadFileSize: 5000,
431+
onError(message) {
432+
console.log(message);
433+
},
434+
onFileChange(files) {
435+
console.log(files[0].alt, files[0].media_type);
436+
},
437+
});

0 commit comments

Comments
 (0)