Skip to content

[EuiIcon] Tighten type interface #9940

Closed as not planned
Closed as not planned

Description

@weronikaolejniczak

Summary

EuiIcon public type / IconType is too wide to catch invalid or removed glyph names at compile time. After icon alias removals, leftover names render as broken <img>s (treated as asset URLs) instead of failing CI.

Currently, EuiIcon interface is loose. iconType accepts | string, effectively overwriting our string union of all acceptable iconType values. The goal is to tighten typing while keeping custom SVGs working.

Problem

Today:

export type EuiIconType = keyof typeof typeToPathMap; // already a string union
export type IconType = EuiIconType | string | ComponentType;

EuiIconType | string effectively is string.

Custom assets is documented API (URL, data URI, React SVG element) and are widely used in Kibana and Cloud UI.

Options

| string has to be dropped no matter what.

// effectively `string`
type IconType = EuiIconType | string | ComponentType;
// instead:
type IconAssetUrl = `http://${string}` | `https://${string}` | `data:${string}` | `blob:${string}`;
type IconType = EuiIconType | IconAssetUrl | ComponentType;

Two more things we can do.

String union (preferred)

Pros: smallest API change, tsc fails on unknown names
Cons: awkward one union member deprecation

UPDATE: removing icons will surface on EUI update PRs where we can handle it. No need for string enum.

String enum

Pros: allows @deprecated, tsc fails on unknown names
Cons: runtime object, bigger declaration file

Goal

  • Named EUI glyphs are a closed type, so invalid / removed names error in a type-check
  • Custom SVGs, URLs, data URIs and React components remain supported
  • Prefer a path that can mark individual glyph names as @deprecated (enum members, deprecated union aliases or equivalent)
  • Do not require migrating every Kibana/Cloud UI icon alongside with the EUI change if we can help it

Activity

  1. eokoneyo commented on Aug 24, 2026

    @eokoneyo
    Contributor

    Nice... we have an open issue in Kibana that relates to this, see elastic/kibana#184643

  2. weronikaolejniczak commented on Aug 24, 2026

    @weronikaolejniczak
    ContributorAuthor

    @eokoneyo this issue is only partially fixing the one you mentioned.

    Allows to specifying icon strings that give validity feedback of icon strings to dev

    Yes ✅ through tsc

    Allows one to defined custom SVG Icons that work in adaptive color mode like so

    This one I'd need some more context on. I'm wondering why currentColor custom SVG passed in type is not working for some use cases?

  3. changed the title [-][Icon] Tighten type interface[/-] [+][EuiIcon] Tighten type interface[/+] on Aug 28, 2026
  4. weronikaolejniczak commented on Aug 28, 2026

    @weronikaolejniczak
    ContributorAuthor

    Dropping | string for template-literal URLs is the right API but IconType is shared (EuiIcon.type, button iconType, tooltips, menus) and used by consumers. Kibana types icons as string in many places. So you can't close it in one place and leave the rest as string, that results in type errors.

    In EUI, closed IconType x button ExclusiveUnion hits TS2590 and has to be fixed first.

    In Kibana, a packed build + type_check is ~700 errors / ~430 files. string-typed wrappers like euiIconType, iconClass, getIconType(): string, test dummies, SVG modules typed as string. Those fields have to be come IconType (or real glyph/URL values) and have cascading type errors.

    Valid names and custom SVGs/URLs still compile.

    Cloud UI will be the same class of work.

    tl;dr; this is not a one-line change, has broad impact and has to be given the appropriate time to tackle meaningfully, preferably starting with migrating on Kibana side. Not on a "Small (2-3d)" type of task (which it is on EUI side).

  5. removed their assignment
    on Aug 28, 2026
  6. weronikaolejniczak commented on Sep 1, 2026

    @weronikaolejniczak
    ContributorAuthor

    We decided to do a meaningful solution by moving icon assets to a separate package with tree-shakeable icon components that we can easily deprecate. See #8909

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions