Skip to content

Conversation

@fahchen
Copy link
Member

@fahchen fahchen commented Dec 21, 2025

Summary

  • Add null option for field types to control nullability explicitly
  • Rewrite README for clarity and conversational tone

Changes

New null option

Fields can now use null: false to prevent nil from being added to their type, or null: true (default) to allow it. This is useful for database records where some fields are always present (like id, inserted_at).

typed_structor do
  field :id, integer(), null: false       # Never nil
  field :name, String.t(), null: true     # Always nullable
end

The option can also be set at the module level:

typed_structor null: false do
  field :id, integer()                    # Not nullable by default
  field :phone, String.t(), null: true    # Override for this field
end

README rewrite

  • Added "Why TypedStructor?" section with before/after comparison
  • Reorganized content into logical sections (Getting Started, Options, Common Patterns, Advanced Features)
  • Made examples more practical and self-contained
  • Improved formatting with callouts and tables

Changelog

- feat: add null option for field types
- docs: rewrite README for clarity and conversational tone

Copilot AI review requested due to automatic review settings December 21, 2025 14:28

This comment was marked as outdated.

This comment was marked as resolved.

fahchen and others added 3 commits December 22, 2025 00:08
Restructure README to show value upfront with before/after comparison,
add behavior table for enforce/default/null interaction, and improve
overall readability while maintaining technical accuracy.
- Remove duplicate 'Parameterized Types' section (already covered in 'Type Parameters')
- Remove duplicate 'Custom Types' section (already covered in 'Opaque Types')
- Fix @moduledoc placement in Documentation example (should be at module level)
- Rename test to accurately describe what it tests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Clarify that null: true is the default behavior
- Condense option tables from 8 rows to 4 using "-" for irrelevant values
- Use consistent column order (default, enforce, null) across tables
- Improve wording for "Providing Defaults" section
@fahchen fahchen force-pushed the feat/null-option-and-readme branch from 1d91b95 to 0835f60 Compare December 21, 2025 15:08
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

field :email, String.t(), enforce: true
end
after
# Struct can be created with nil for nullable fields
Copy link

Copilot AI Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment could be misleading. The test demonstrates that fields can be nil at runtime even with null: false (line 47), not just "nullable fields". Consider revising to clarify that the null option only affects the type specification, not runtime behavior. For example: "Fields can hold nil at runtime regardless of null option".

Suggested change
# Struct can be created with nil for nullable fields
# Struct fields can be nil at runtime regardless of null option in the type spec

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants