Skip to content
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

vscode jsdoc import module type def not imported #22884

Closed
mjbvz opened this issue Mar 26, 2018 · 2 comments
Closed

vscode jsdoc import module type def not imported #22884

mjbvz opened this issue Mar 26, 2018 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Mar 26, 2018

From @shivshankar3578 on March 24, 2018 11:9

@VScode:1.21
@node: 8.10

mod.js

/**
 *  @module mod
 */

/**
 * @typedef {Object} foobar
 * @property {String} foo
 * @property {Boolean} [bar] - Optional value
 */

/**
 * 
 * 
 * @param {string} foo 
 * @param {string} bar 
 * @return {foobar} 
 */
function doSomething (foo, bar) {
  console.log(foo, bar);
  // do something
  return {
	foo : foo,
	bar : bar
  }
}

let n = doSomething('a', 'b');

module.exports  = doSomething;

jsdoc.js

const mod = require('./mod');
let n = new mod('a', 'b'); 
console.log(n)

pic-1 n:foobar

pic-1

then why n:any here

pic-2

while imported module have foobar return type

pic-3

Copied from original issue: microsoft/vscode#46463

@mjbvz
Copy link
Contributor Author

mjbvz commented Mar 26, 2018

Possibly covered by #14844

@mhegazy mhegazy added Bug A bug in TypeScript Salsa labels Mar 26, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Mar 26, 2018
@sandersn
Copy link
Member

In jsdoc.js, you use new, but without assignments to this properties inside of doSomething, the compiler doesn't recognise it as newable and falls back to any. You'll also get an error if you add // @ts-check at the beginning of the file, because we think that newing a function with no this property assignment is very suspicious.

If you call mod directly as you did on mod.js:27, you will see the correct type for n.

@sandersn sandersn added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants