Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Typed Laravel Package

spatie/typed

Userland improved PHP type system with type inference and runtime checking: generics, union types, typed collections/lists, tuples, and structs. Proof-of-concept package from Spatie to add stronger type guarantees without language-level support.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Enhanced Developer Productivity: Adopting spatie/typed enables teams to leverage stricter type safety in PHP/Laravel, reducing runtime errors and improving code maintainability. This aligns with roadmaps prioritizing developer experience (DX) and reducing technical debt.
  • Build vs. Buy: A "build" decision for teams already invested in PHP/Laravel, as it provides a lightweight, open-source solution to fill gaps in PHP’s native type system (e.g., generics, tuples) without vendor lock-in.
  • Scalability for Complex Systems: Ideal for projects with intricate data structures (e.g., APIs, microservices) where type safety directly impacts reliability. Supports roadmap items like migrating legacy codebases to typed architectures.
  • Consistency Across Teams: Standardizes type conventions (e.g., structs for DTOs) across engineering teams, reducing onboarding friction and enforcing best practices.
  • Legacy Modernization: Enables incremental adoption of typed patterns in older Laravel/PHP codebases without full framework upgrades.

When to Consider This Package

  • Adopt When:

    • Your team prioritizes type safety over rapid iteration (e.g., financial systems, healthcare apps).
    • You’re building complex data pipelines (e.g., event sourcing, graphQL resolvers) where tuples/structs improve clarity.
    • Legacy code lacks type hints, and you want to retrofit types without rewriting core logic.
    • You’re using Laravel but need generics (e.g., for repository patterns or polymorphic relationships).
    • Your stack is PHP 7.4+ (required for some features) and you’re open to userland solutions.
  • Look Elsewhere If:

    • Your team lacks PHP type discipline or resists static analysis tools (this adds friction without buy-in).
    • You need active maintenance (package is archived; consider alternatives like phpstan/extension-installer or rector).
    • Your project is simple CRUD with minimal type complexity (overkill for basic use cases).
    • You’re tied to PHP 8.0+ and can use native features (e.g., array<Key, Value> syntax).
    • Security/compliance requires audited, actively maintained dependencies (MIT license is permissive but not enterprise-grade).

How to Pitch It (Stakeholders)

For Executives: "This package lets our PHP/Laravel teams write more reliable code with fewer bugs—like adding a ‘type checker’ for complex data structures without switching languages. For example, it lets us enforce rules like ‘this API response must always include a userId and timestamp tuple,’ catching errors early. It’s a lightweight upgrade that aligns with our tech debt reduction goals and scales with our move into microservices. The tradeoff? A small learning curve for developers, but the payoff is fewer production fires and faster onboarding for new hires."

For Engineering: "Spatie’s typed fills critical gaps in PHP’s type system (generics, structs, tuples) that we’d otherwise have to build manually or ignore. For instance:

  • Structs: Replace magic __get() DTOs with compile-time safety (e.g., UserStruct::fromArray($data)).
  • Tuples: Model fixed-width data (e.g., (string, int) for UserId + Timestamp) without hacks.
  • Generics: Type-safe collections (e.g., List<User>) for repositories or caching layers. It’s archived but stable—we’d pair it with PHPStan for full static analysis. The effort to adopt is low (1–2 dev days), and the ROI is higher confidence in refactors and new features. Alternatives like phpstan are heavier; this is the ‘just enough’ solution."
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport