Make the @adonisjs/inertia Inertia class macroable #5121
Replies: 1 comment · 2 replies
|
While testing adonis-modal I ran into a typing issue worth raising here, and I think it shows that Macroable on its own won't cover everything. Right now I set up the type augmentation like this: declare module '@adonisjs/inertia' {
interface Inertia<Pages> {
modal(...): ModalResponse
}
}It works fine in a normal server tsconfig, but it breaks around the barrel. In a second TS program that type-checks a caller of Macroable would clean up the runtime side, but not this. The class stays reachable only through the re-export, so the merge keeps failing in programs that don't load the barrel. Compare that with Would it make sense to also expose an augmentable |
Uh oh!
There was an error while loading. Please reload this page.
Feature request: Make Inertia extend Macroable
Proposal
Make the
Inertiaclass from@adonisjs/inertiaextend@poppinss/macroable, allowing packages and applications to add methods usingInertia.macro()andInertia.getter(), similar to other AdonisJS core classes such asRequestandResponse.Motivation
At the moment, there is no official extension point for the
Inertiainstance.Packages that need to add custom methods currently have to patch
Inertia.prototypedirectly, which is:Providing Macroable support would offer a familiar and officially supported mechanism for extending Inertia.
Example
A package could register a custom method as follows:
with typings provided through module augmentation.
Real-world use case
I maintain
adonis-inertia-modal, a package that provides backend-driven modals for Inertia.js applications on AdonisJS.Today, the package patches
Inertia.prototype.modal. With Macroable support, it could use the standard AdonisJS extension mechanism instead.Scope
This should be a small, non-breaking change:
InertiaextendMacroable.super()in the constructor.@poppinss/macroableas a dependency.I'd be happy to open a PR if this approach aligns with the project's direction.
https://github.com/filipebraida/inertia/tree/feat/macroable
All reactions