tinymce / tinymce-react

Offical TinyMCE React component
MIT License
937 stars 152 forks source link

expose interfaces for typescript #454

Closed megacherry closed 1 year ago

megacherry commented 1 year ago

I just wrote a function that handles the upload and need the BlobInfo interface for it. Unfortunately the interfaces are not exported.

Can interfaces be exported?

TinyITAdmin commented 1 year ago

Ref: INT-3177

tiny-james commented 1 year ago

This question should be asked on the tinymce repository as it is related to TinyMCE not this react integration.

The interfaces are available but you have to go via the editor options.

// get the type from the tinymce repository
import { EditorOptions  } from 'tinymce';

// when you assign the upload handler type it will give blob and progress the correct types
const upload: EditorOptions['images_upload_handler'] = async (blob, progress) => {
  return "image.jpg";
}

Alternatively you can extract the BlobInfo type from the method parameters:

type BlobInfo = Parameters<NonNullable<EditorOptions['images_upload_handler']>>[0];
megacherry commented 1 year ago

Thank you :)