Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#65344 [@wordpress/editor] fix type functio…
Browse files Browse the repository at this point in the history
…n uploadMedia() by @yusuke-omae

Co-authored-by: segayuu <segayuu@gmail.com>
  • Loading branch information
yusuke-omae and segayuu authored May 17, 2023
1 parent 596daba commit da89ad3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
9 changes: 8 additions & 1 deletion types/wordpress__editor/utils/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
export { uploadMedia as mediaUpload } from '@wordpress/media-utils';
import type { UploadMediaOptions } from '@wordpress/media-utils';

export type MediaUploadOptions = Omit<UploadMediaOptions, 'maxUploadFileSize' | 'onError' | 'wpAllowedMimeTypes'> &
Partial<Pick<UploadMediaOptions, 'maxUploadFileSize'>> & {
onError?(message: string): void;
};

export function mediaUpload(options: MediaUploadOptions): void;

/**
* Performs some basic cleanup of a string for use as a post slug
Expand Down
31 changes: 31 additions & 0 deletions types/wordpress__editor/wordpress__editor-tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { dispatch, select } from '@wordpress/data';
import * as e from '@wordpress/editor';

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

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

// $ExpectType boolean
select('core/editor').inSomeHistory(state => state.foo === true);

//
// Utils
// ============================================================================

// $ExpectType void
e.mediaUpload({
filesList: FILELIST,
onFileChange(files) {
console.log(files[0].alt, files[0].media_type);
},
});

// $ExpectType void
e.mediaUpload({
additionalData: {
foo: 'foo',
bar: ['bar', 'baz'],
},
allowedTypes: ['image/jpeg'],
filesList: FILE_ARRAY,
maxUploadFileSize: 5000,
onError(message) {
console.log(message);
},
onFileChange(files) {
console.log(files[0].alt, files[0].media_type);
},
});

0 comments on commit da89ad3

Please sign in to comment.