Skip to content

How can I access Node type interfaces inside "modules"? #26891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Sequoia opened this issue May 18, 2017 · 1 comment
Closed

How can I access Node type interfaces inside "modules"? #26891

Sequoia opened this issue May 18, 2017 · 1 comment
Assignees
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)

Comments

@Sequoia
Copy link

Sequoia commented May 18, 2017

myHandler.js

/**
 * @param {NodeJS.http.IncomingMessage} req 
 * @param {http.IncomingMessage} res 
 */
function handleRequest(req, res){
  req._
}

Node built in (or ATA'd) types:

//...
declare module "http" {
//...
    export interface IncomingMessage extends stream.Readable {

Expected

I can somehow mark req in my function as being of type http.IncomingMessage

Actual

It's impossible to get these types linked unless I manually create an object thus

const req = new (require('http').IncomingMessage);

Or use a function that http exposes that uses that type like createServer.

@mjbvz mjbvz self-assigned this May 18, 2017
@mjbvz mjbvz added javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code) labels May 19, 2017
@mjbvz
Copy link
Collaborator

mjbvz commented May 19, 2017

One options:

import * as http from 'http'

/**
 * @param {http.IncomingMessage} req 
 * @param {http.IncomingMessage} res 
 */
function handleRequest(req, res){
  req._
}

We currently don't support this properly when using require though. We tracking better support here on the TypeScript side: microsoft/TypeScript#14056

We are also investigating a better solution for this in JavaScript files: microsoft/TypeScript#14377

Closing as upstream

@mjbvz mjbvz closed this as completed May 19, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
javascript JavaScript support issues upstream Issue identified as 'upstream' component related (exists outside of VS Code)
Projects
None yet
Development

No branches or pull requests

2 participants