Missing/wrong types for Context
See original GitHub issueDescribe the bug
I have a middleware which is using $axios
and req.originalUrl
from Context
. Both of these work fine in runtime, but are missing in the types.
To Reproduce
- Create a middleware with this contents:
import { Context } from '@nuxt/types'
export default async function({ $axios, req }: Context) {
console.log($axios)
console.log(req.originalUrl)
}
- Observe that the following typescript errors occur:
Property ‘$axios’ does not exist on type ‘Context’. Property ‘originalUrl’ does not exist on type ‘IncomingMessage’.
- Make a request to the server and observe that it logs an axios instance and a path string.
Expected behavior
The types should be present and correct. I’m not completely sure about the types, but I think $axios
should be of type AxiosInstance
from axios
and req
should be of type Request
from express
.
As an aside, the documentation at https://nuxtjs.org/api/context which doesn’t mention $axios
and says that req
is http.Request
/http.IncomingMessage
should preferably also be changed.
Additional context Versions: nuxt: 2.10.2 @nuxt/typescript-build: 0.3.3 @nuxt/typescript-runtime: 0.2.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
https://github.com/nuxt/typescript/issues/180#issuecomment-549456811 ->
@nuxtjs/axios
needs to be added totypes
array oftsconfig.json
to not have to import it in your middleware.https://github.com/nuxt/typescript/issues/180#issuecomment-549481441 -> Well I’m not sure what is the type, maybe diving into Nuxt core may result on finding where it’s defined and then determine the type. I’m lacking time to do so for now (busy with main job work), any help is appreciated then 😃
@kevinmarrec: You need to change the class used, so the bot won’t do it. I’ve created PR #251 for it.