facebookarchive / draft-js

A React framework for building text editors.
https://draftjs.org/
MIT License
22.56k stars 2.64k forks source link

why draftInlineStyleType only can be default type? #3173

Closed chenjiashrimp closed 1 year ago

chenjiashrimp commented 1 year ago

I defined editorStyleMap and use them const editorStyleMap = { Choose: { color: '#4880f0' }, Black: { color: '#000000' } } then I get the array of inlineStyleRanges const messageBlocks=convertToRaw(editorState.getCurrentContent()).blocks[0].inlineStyleRanges; i console every item of the array and the result is below, item's style can be 'Choose' or 'Black'

{offset: 3, length: 3, style: 'Choose'} {offset: 6, length: 5, style: 'Black'} {offset: 11, length: 3, style: 'Choose'} {offset: 14, length: 1, style: 'Black'}

but when i want to use if to judge the type of style if(item.style==='Choose')

terminal reports an error 'This condition will always return 'false' since the types 'DraftInlineStyleType' and '"Choose"' have no overlap.' it seems that styleType only can be default type like 'BOLD' and 'ITALIC'.

i don't know why??? if you could help me, i would be grateful:)

chenjiashrimp commented 1 year ago

i use a strange way to solve that. use String() to convert style to string type, and it can be 'Choose' or 'Black'