Updates dangerouslySetInnerHTML type so future TS will accept Trusted… by lukewarlow · Pull Request #4930 · preactjs/preact (original) (raw)
…HTML automatically
Need to see if there's tests for this, and how to update them.
coverage: 99.535%. remained the same
when pulling 428bace on lukewarlow:update-dangerouslySetInnerHTML-types-for-tt
into 5e18356 on preactjs:main.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Just to expound: parseFromString should take A TrustedHTML or string instance defining HTML to be parsed., though TS has yet to update lib/dom.d.ts to account for this. The method here should in theory be future proof though and collect the correct types for .innerHTML when/if TS makes them available.
Quite crafty
To provide a bit of extra detail we can't do something using innerHTML itself as that is currently a property but might become a getter setter pair and there's not a TS way to handle both those cases, nor does there seem to be a way to get the setter type, so this is a hack to get string | TrustedHTML in a workable way.
This was referenced
Oct 23, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})