# Prospective changes to AnnotatedString and StyledStrings

**URL:** <https://discourse.julialang.org/t/prospective-changes-to-annotatedstring-and-styledstrings/134847>\
**Category:** Internals & Design\
**Tags:** stdlib\
**Created:** [January 2, 2026, 7:40pm UTC](https://discourse.julialang.org/t/prospective-changes-to-annotatedstring-and-styledstrings/134847 "2026-01-02T19:40:32Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)\
**Post date:** [March 29, 2026, 5:41pm UTC](https://discourse.julialang.org/t/prospective-changes-to-annotatedstring-and-styledstrings/134847/21 "2026-03-29T17:41:18Z")

</div>

I may have misunderstood your advice @tecosaur.

In my package extension to XLSX.jl, I’ve written:

```julia-auto
setdata!(sheet::Worksheet, ref::CellRef, ss::AnnotatedString{T}) where T = setdata!(sheet, ref, RichTextString(_ssToRuns(ss)))

@static if VERSION >= v"1.14-"
        const _SS_ARG = Union{<:AnnotatedString{>:Face}, SubString{<:AnnotatedString{>:Face}}}
    else
        const _SS_ARG = Union{<:AnnotatedString, SubString{<:AnnotatedString}}
    end

function _ssToRuns(s::_SS_ARG)
    # Do some stuff
end

```

It works perfectly for pre-1.14.

However, in v1.14, I get

```julia-auto
ERROR: MethodError: no method matching _ssToRuns(::AnnotatedString{String})
The function `_ssToRuns` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  _ssToRuns(::Union{AnnotatedString{>:StyledStrings.Face}, SubString{<:AnnotatedString{>:StyledStrings.Face}}})
   @ StyledStringsSstsExt C:\Users\Tim Gebbels\OneDrive\Documents\Julia\XLSX v0.11\XLSX.jl\ext\StyledStringsSstsExt.jl:38

```

In the REPL, I can do:

```julia-auto
julia> using StyledStrings, XLSX

julia> s=styled"{yellow:hello} {blue:there}"
"hello there"

julia> typeof(s)
AnnotatedString{String}

julia> s isa AnnotatedString{>:StyledStrings.Face}
false

```

I’m generally not very clever at understanding Julia’s type system and I’ve obviously got something wrong here.

Is there anything obvious you can suggest?

---

<div class="post-metadata">

**Author:** ![TimG](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimG](https://discourse.julialang.org/u/TimG)\
**Post date:** [March 31, 2026, 10:15am UTC](https://discourse.julialang.org/t/prospective-changes-to-annotatedstring-and-styledstrings/134847/22 "2026-03-31T10:15:31Z")

</div>

I’ve got things working now.

As suggested in the StylesStrings.jl docs, I’ve opened [an issue](https://github.com/JuliaLang/StyledStrings.jl/issues/134) to request making some currently internal functions public.

---

<div class="post-metadata">

**Author:** ![tecosaur](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tecosaur/32/23206_2.png) [@tecosaur](https://discourse.julialang.org/u/tecosaur)\
**Post date:** [September 21, 2026, 5:46pm UTC](https://discourse.julialang.org/t/prospective-changes-to-annotatedstring-and-styledstrings/134847/23 "2026-09-21T17:46:56Z")

</div>

For anybody wondering what’s happened to [Face primacy and palettes - Pull Request #131 - JuliaLang/StyledStrings.jl - GitHub](https://github.com/JuliaLang/StyledStrings.jl/pull/131), the short answer is that making sure that the particular design compromises are _right_ (no piracy, no invalidations, not digging a hole for ourselves, etc.) has been _difficult_.

I’ve continued coming back to this problem though (and bothering Cody), and I think this set of changes in now in a pretty decent state.

Since I’ve been thinking hard about the guts of the code, I’ve also landed a few performance improvements on top, ending up with ~5x the performance of 1.13’s StyledStrings.jl, which actually has us beating `printstyled` for all but the most trivial cases (i.e. print a single coloured word once, that’s it) even with all of the extra capabilities.

With the PR, it’s also possible to use StyledStrings.jl with JuliaC in `--trim=safe` mode.

I’m pretty chuffed with this.

[Previous page](https://discourse.julialang.org/t/prospective-changes-to-annotatedstring-and-styledstrings/134847.md?page=1)
