Explicitly Specifying types for Express’ “application, request, response…”

Classic case of “work on something for a while with no success, but when you finally post a question asking for help, you figure it out immediately”.

The solution:
When you want to use one of the types, you have to import the module as the typedef is in a named module within the typedef.

In the above code (that resided in my app.ts), I was getting the type annotations on app. Because my import statement at the top of the file was import express = require('express');, I could annotate the req & res params like this:

app.get("https://stackoverflow.com/", function(req:express.Request, res:express.Response){});

In other files, where I was trying to get type annotations on the app, I was missing the import statement at the top of the file. Once added, I could add the annotations for that as well like:

public init(app: express.Application){}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)