Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Typescript DraftBlockType too strict? #1453

Closed
camurai opened this issue Oct 25, 2017 · 3 comments
Closed

Typescript DraftBlockType too strict? #1453

camurai opened this issue Oct 25, 2017 · 3 comments
Assignees
Labels

Comments

@camurai
Copy link

camurai commented Oct 25, 2017

Its possible that I am missing an obvious way I am supposed to be doing this, but it seems like the DraftBlockType is too specific, making it impossible to add in custom block types in typescript. I was following the example found in the docs here:
https://draftjs.org/docs/advanced-topics-block-components.html#content

Trying to use the code in the example in a typescript project, I got the following error, coming from the line where the Editor object is created in the render function:

 Type 'string' is not assignable to type '"unstyled" | "paragraph" | "header-one" | "header-two" | "header-three" | "header-four" | "header...'.

This seems to stem from the fact that blockRenderMap is expecting a Immutable.Map<DraftBlockType, any>, while anything I create with the merge will have to be Immutable.Map<string, any>

I've tried setting the types, but since DraftBlockType does not contain my custom block type, and blockRenderMap expects the key to be DraftBlockType, no custom Block types can be added.

To test things out I edited the type for DraftBlockType in the node-module and set it to just be "string" instead of "unstyled" | "paragraph" | ....
This seems to make it so I am able to compile without the error messages.

So is there a different way to create a Custom Block Component that gets around the DraftBlockType, or was DraftBlockType just made too strict when the type file was setup?

@mitermayer mitermayer added the bug label Oct 30, 2017
@mitermayer
Copy link
Contributor

Hi @camurai,

Thanks for reporting this issue

@xFloooo
Copy link

xFloooo commented Mar 15, 2018

@mitermayer
Copy link
Contributor

Hi @xFloooo,

DefinitelyTyped is a community driven repository, you should submit an issue/PR to that repo for requesting this changes.

midas19910709 added a commit to midas19910709/draft-js that referenced this issue Mar 30, 2022
Summary:
DraftBlockType needs to be less strict in order to allow user defined block types however we also want to retain a way to identify our core draft blocks.

fixes: facebookarchive/draft-js#1453
Closes facebookarchive/draft-js#1480

Differential Revision: D6215628

fbshipit-source-id: e4647bf2bafe9adb7788740ec64c1445e307e632
alicayan008 pushed a commit to alicayan008/draft-js that referenced this issue Jul 4, 2023
Summary:
DraftBlockType needs to be less strict in order to allow user defined block types however we also want to retain a way to identify our core draft blocks.

fixes: facebookarchive/draft-js#1453
Closes facebookarchive/draft-js#1480

Differential Revision: D6215628

fbshipit-source-id: e4647bf2bafe9adb7788740ec64c1445e307e632
aforismesen added a commit to aforismesen/draft-js that referenced this issue Jul 12, 2024
Summary:
DraftBlockType needs to be less strict in order to allow user defined block types however we also want to retain a way to identify our core draft blocks.

fixes: facebookarchive/draft-js#1453
Closes facebookarchive/draft-js#1480

Differential Revision: D6215628

fbshipit-source-id: e4647bf2bafe9adb7788740ec64c1445e307e632
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants