Closed TuurDutoit closed 1 year ago
@TuurDutoit you are correct in that only interfaces can be augmented; appreciate the fix, thank you! Will approve as soon as CI passes.
@jsamr ah right, didn't notice that! I fixed the issue and yarn test
is passing locally for me now.
Merging #606 (77be4d8) into master (7c79513) will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## master #606 +/- ##
=======================================
Coverage 76.92% 76.92%
=======================================
Files 83 83
Lines 637 637
Branches 147 147
=======================================
Hits 490 490
Misses 7 7
Partials 140 140
:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more
Checks
Description
We are using this library to render HTML in several places in the DataCamp app. We have a custom renderer for
<img>
tags, which we need to pass some extra config (props) to. I tried using TypeScript module augmentation to add those props to theRenderersProps['img']
type, as the docs suggest:Unfortunately, this didn't work: the new field was not picked up by TS. Apparently, you can add new properties on the
RenderersProps
type this way (i.e. for new element types), but you can't update the built-in ones, as they are anonymous object types. For example, the following does work as expected:However, this is not what we needed: we want to add a prop for an existing element. By moving those types to named interfaces, it's now possible to extend them: