Make the HttpContextContract
a generic interface
#4210
ndianabasi
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
I just tried this and it worked: type Params = {
user_id?: string
organisation_id?: string
}
export default class ExampleController {
// Using type intersection 👇
public async store({ request, bouncer, params }: HttpContextContract & { params: Params }) {
// Strongly-typed `organisation_id`
if (params.organisation_id) {
}
// Strongly-typed `user_id`
if (params.user_id) {
}
}
} However, using a generic interface is neater. |
Beta Was this translation helpful? Give feedback.
0 replies
-
In my opinion, it would be better to use assertion to ensure your params are defined. Using generic here does not bring any validation or security. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I've felt handicapped by the inability to type the
params
context property all through my journey withV5
. It would wonderful ifV6
makes theHttpContextContract
interface a generic one so that theparams
property by the typed by the developer.Example:
Beta Was this translation helpful? Give feedback.
All reactions