question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing/wrong types for Context

See original GitHub issue

Describe 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

  1. 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)
}
  1. Observe that the following typescript errors occur:

Property ‘$axios’ does not exist on type ‘Context’. Property ‘originalUrl’ does not exist on type ‘IncomingMessage’.

  1. 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:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
kevinmarreccommented, Nov 5, 2019
  1. https://github.com/nuxt/typescript/issues/180#issuecomment-549456811 -> @nuxtjs/axios needs to be added to types array of tsconfig.json to not have to import it in your middleware.

  2. 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 😃

1reaction
trygveaacommented, Dec 18, 2019

@kevinmarrec: You need to change the class used, so the bot won’t do it. I’ve created PR #251 for it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Context | React TypeScript Cheatsheets
Using createContext with an empty object as default value. interface ContextState { // set the type ...
Read more >
golang
type MissingError. func (m *MissingError) Error() string. type Package. func (p *Package) EachUnit(ctx context.Context, .
Read more >
How to use React Context with TypeScript
Create the to-do type; Create the context; Create the components and consume the context; Provide the context; Theming with the Context API.
Read more >
Options.Applicative.Types
An OptReader defines whether an option matches an command line argument. Constructors. OptReader [OptName] (CReader a) (String -> ParseError). option reader.
Read more >
Missing/Wrong data from different API calls for meetings
Additional context. While testing different endpoints, I noticed that there are inconsistent or wrong information being returned.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found