This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Superclass is a Dart code generation library that brings TypeScript Utility Types to Dart. It uses build_runner and source_gen to generate variations of existing types without manual duplication.
The project is a monorepo using Dart workspaces with two main packages:
packages/superclass/: Core annotations package defining the TypeScript-like utility typespackages/superclass_generator/: Code generator that processes the annotations
The generator creates .superclass.dart files and is configured to run before freezed and json_serializable generators for proper integration.
cd packages/superclass_generator/example
dart run build_runner build --delete-conflicting-outputscd packages/superclass_generator
dart analyzedart pub getThe library provides TypeScript-like utility type annotations:
Merge<T1, T2>: Merge two types togetherOmit<T>: Create a type with specific fields omittedMakePartial<T>: Make all fields optional or specific fields viaonlyFieldsPick<T>: Create a type with only specific fieldsMakeRequired<T>: Make all fields required or specific fields viaonlyFieldsRename<T>: Rename fields using a mapping for API compatibilityIntersect<T1, T2>: Keep only fields that exist in both typesDiff<T1, T2>: Keep fields that exist in T1 but not in T2Transform<T>: Transform field types using a mapping for serializationWithDefaults<T>: Add default values to fields (automatically handles Freezed @Default() annotations)$PR(Previous Result): Special type for chaining operations in theapplylist
The $PR type allows chaining multiple transformations where each operation works on the result of the previous one:
@Superclass(
apply: [
Omit<User>(fields: {'email'}), // Step 1: Remove email field
MakePartial<$PR>(), // Step 2: Make remaining fields optional
Merge<$PR, Address>(), // Step 3: Add address fields
],
)
typedef UserForm = $UserForm;The main generator logic is in packages/superclass_generator/lib/src/generator.dart. It:
- Processes
@Superclassannotations on typedefs - Applies the specified utility type modifiers (in
lib/src/modifiers/) - Generates new Dart classes with the transformed fields
- Optionally includes Freezed and JSON serialization support
- The generator uses the analyzer package's AST to process type information
- Build configuration is in
packages/superclass_generator/build.yaml - The project currently has analyzer deprecation warnings that should be addressed by migrating to the new element model
- No tests are currently implemented despite test infrastructure being set up
- Comprehensive documentation with $PR examples is in
packages/superclass/README.md - Working examples demonstrating $PR chaining are in
packages/superclass_generator/example/lib/example.dart
The $PR class is defined in packages/superclass/lib/superclass.dart as a simple marker type. The generator recognizes when a type parameter is $PR and substitutes it with the fields from the previous transformation in the chain. This is handled in packages/superclass_generator/lib/src/utils/helpers.dart where the ClassElementExtension.validMappedFieldsOrFields method checks if the class name is $PR and returns the accumulated fields instead of the class's own fields.