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

Cannot set Type of module.exports using JSDocs #15187

Closed
mjbvz opened this issue Apr 14, 2017 · 3 comments
Closed

Cannot set Type of module.exports using JSDocs #15187

mjbvz opened this issue Apr 14, 2017 · 3 comments
Assignees
Labels
Duplicate An existing issue was already created VS Code Tracked There is a VS Code equivalent to this issue

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Apr 14, 2017

From: microsoft/vscode#24657

TypeScript Version: 2.3.1-insiders

Code

For the JavaScript:

class Foo { }

/**
 * @type {Foo}
 */
module.exports = {}

/**
 * @type {Foo}
 */
const exp = {}

Expected behavior:
The type of module.exports and exp are both Foo

Actual behavior:
The type of module.exports is any. The type of exp is Foo

@mjbvz mjbvz added the VS Code Tracked There is a VS Code equivalent to this issue label Apr 14, 2017
@Jessidhia
Copy link

The problem here is that @type applies only to var/let/const declarations, not to expressions. It also doesn't work for setting the type of an object key, for example:

// @ts-check

const foo = {
  /** @type {string|null} */
  bar: null
}
foo.bar = '' // type error

@mhegazy
Copy link
Contributor

mhegazy commented Apr 17, 2017

module.exports = {} is not a declaration, it is just an assignment, and you can have multiple of these in a single file.

@Kovensky's suggestion is more attainable. keeping this issue open to enable that.

@mhegazy mhegazy added this to the TypeScript 2.4 milestone Apr 17, 2017
@mhegazy mhegazy added Bug A bug in TypeScript Salsa labels Apr 17, 2017
@mhegazy
Copy link
Contributor

mhegazy commented May 11, 2017

#13306 is already tracking @Kovensky's suggestion.

@mhegazy mhegazy added Duplicate An existing issue was already created and removed Bug A bug in TypeScript Salsa labels May 11, 2017
@mhegazy mhegazy closed this as completed May 11, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created VS Code Tracked There is a VS Code equivalent to this issue
Projects
None yet
Development

No branches or pull requests

4 participants