Dart Seal Type Hierarchies logo

Dart Seal Type Hierarchies

Community
kevmoo
dart-seal-type-hierarchies

Identify closed type hierarchies that are not declared `sealed`, and seal them so the compiler can enforce switch exhaustiveness. Covers the same-library requirement, the public-API breaking-change tradeoff, and the migration from `is` cascades to exhaustive switches.

Overview

Publisherkevmoo
Repositorydash_skills
Skill namedart-seal-type-hierarchies
Stars
148
Forks
16
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by kevmoo on GitHub. Read the source before you install it.

Installation

Install the Dart Seal Type Hierarchies AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/kevmoo/dash_skills/tree/main/skills/dart-seal-type-hierarchies
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/kevmoo/dash_skills.git /tmp/dash_skills
mkdir -p .claude/skills
cp -r /tmp/dash_skills/skills/dart-seal-type-hierarchies .claude/skills/dart-seal-type-hierarchies
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Dart Seal Type Hierarchies in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Dart Seal Type Hierarchies on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Dart Seal Type Hierarchies is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Seal Type Hierarchies

1. When to use this skill

Use this skill when:

  • A package declares an abstract base type whose subtypes are all defined in the same library, but the base type is not marked sealed.
  • Code branches over the members of such a hierarchy with is checks or a non-exhaustive switch, so adding a subtype later fails silently at runtime instead of loudly at compile time.
  • Reviewing a new type hierarchy and deciding whether it should be open to external subtyping.

When NOT to use (Abstention Guardrails)

Do NOT seal a type when:

  • Subtypes span multiple libraries: sealed requires every direct subtype to be declared in the same library as the base type. If subtypes live in other files (and are not part of the same library), the code will not compile. Either move them or leave the hierarchy open.
  • The type is public API and external extension is intended: Sealing a type exported from a published package is a breaking change for any downstream package that extends or implements it. Plugin interfaces, visitor bases, and extension points are meant to be open. Do not seal them to win exhaustiveness.
  • The base type is concrete and instantiated: sealed implies abstract. If callers construct the base type directly, sealing it breaks them, and the fix is a larger refactor than this skill covers.
  • Fewer than two subtypes: A single subtype is specialization, not an algebraic hierarchy. Exhaustiveness checking buys nothing.
  • SDK constraint below 3.0.0: Class modifiers do not exist before Dart 3. Check environment.sdk in pubspec.yaml first.

2. Why sealing is the correctness move

The value is not switch syntax. It is that the compiler starts rejecting incomplete branching:

seal the hierarchy -> exhaustiveness checking -> adding a subtype becomes
a compile error at every switch, instead of a silent fallthrough

An unsealed hierarchy with is cascades is not wrong today. It becomes wrong the moment someone adds a subtype, and nothing tells them which call sites they missed. Sealing is prophylactic: it converts a future runtime bug into a present-day compile error.

This is a different concern from preferring pattern matching for readability. Pattern matching over an unsealed hierarchy is a style choice. Sealing the hierarchy is a correctness guarantee, and the ergonomic payoff is a consequence, not the goal.

3. Detection

A type is a candidate when all of the following hold:

  1. It is declared abstract and is not already sealed.
  2. It has two or more direct subtypes.
  3. Every direct subtype is declared in the same library as the base type.
  4. Sealing it is not a breaking change: it lives under lib/src/, or is already marked final, or the package is an application rather than a published library.

Conditions 1 through 3 are decidable from the syntax tree. Condition 4 requires knowing the author's intent about the public API and is the part a human or an LLM must confirm.

This detection is not expressible as a single-file regular expression. It is a question about the package-wide type graph: you must collect every type declaration and every extends/implements/with edge before you can tell whether a hierarchy is closed.

4. Applying the change

Before

dart
abstract class Shape {}

class Circle extends Shape {
  final double radius;
  Circle(this.radius);
}

class Square extends Shape {
  final double side;
  Square(this.side);
}

double area(Shape shape) {
  if (shape is Circle) {
    return 3.14159 * shape.radius * shape.radius;
  } else if (shape is Square) {
    return shape.side * shape.side;
  }
  // Silently reached when a new subtype is added.
  throw ArgumentError('Unknown shape: $shape');
}

After

dart
sealed class Shape {}

final class Circle extends Shape {
  final double radius;
  Circle(this.radius);
}

final class Square extends Shape {
  final double side;
  Square(this.side);
}

double area(Shape shape) => switch (shape) {
  Circle(:final radius) => 3.14159 * radius * radius,
  Square(:final side) => side * side,
};

Adding class Triangle extends Shape now produces a compile error at area, naming the missing case. The throw and its unreachable-by-construction error message are gone.

Migration steps

  1. Add sealed to the base type declaration.
  2. Run dart analyze. Every non-exhaustive switch over the hierarchy now reports an error; every subtype declared outside the library reports one too.
  3. Convert is cascades to switch expressions, removing the trailing throw/default that existed only to satisfy the return type.
  4. Consider marking leaf subtypes final to prevent further extension.

5. Interaction with other skills

  • dart-use-pattern-matching / dart-modern-features: apply after sealing. Rewriting an is cascade as a switch over an unsealed type is a readability change only; the same rewrite over a sealed type is checked by the compiler.
  • Do not treat this skill as a reason to seal a hierarchy you do not own the evolution of.

Frequently asked questions

What does the Dart Seal Type Hierarchies AI skill do?

Identify closed type hierarchies that are not declared `sealed`, and seal them so the compiler can enforce switch exhaustiveness. Covers the same-library requirement, the public-API breaking-change tradeoff, and the migration from `is` cascades to exhaustive switches.

Why use Dart Seal Type Hierarchies on TypingMind?

Because you install it once and use it with any model. Dart Seal Type Hierarchies is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Dart Seal Type Hierarchies in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/kevmoo/dash_skills/tree/main/skills/dart-seal-type-hierarchies. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Dart Seal Type Hierarchies?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Dart Seal Type Hierarchies?

As many as you like. As long as a model supports skills, you can use Dart Seal Type Hierarchies with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Dart Seal Type Hierarchies AI skill free?

Yes. It is published on GitHub by kevmoo under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇