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

Salsa does not support @type annotation in object member #13306

Closed
Jessidhia opened this issue Jan 6, 2017 · 2 comments
Closed

Salsa does not support @type annotation in object member #13306

Jessidhia opened this issue Jan 6, 2017 · 2 comments
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue

Comments

@Jessidhia
Copy link

Jessidhia commented Jan 6, 2017

TypeScript Version: 2.2.0-dev.20170102 (--strictNullChecks)

Code

const obj = {
  /** @type {string|undefined} */
  foo: undefined
}
obj.foo = 'string'
obj.foo // type is `undefined`

Expected behavior:

Type of obj.foo to be string | undefined

Current workaround is something like:

const obj = {
  foo: (/** @returns {string|undefined} */() => undefined)()
}
obj.foo // type is `string | undefined`

A @type annotation could also be placed in the obj itself, but that gets unwieldy when the object itself is large.

Putting all these things in an object like this is arguably an anti-pattern (should be a module or class instead), but it's a start when adapting decade-old legacy code :)

Possibly related to #5158 as supporting its "assertion-y" use would make for a simpler workaround that doesn't require an IIFE.

@mohsen1
Copy link
Contributor

mohsen1 commented Jan 6, 2017

Is this issue related? microsoft/vscode#18184

@Jessidhia
Copy link
Author

Nope, that seems to be about VS Code 1.8's automatic @types acquisition. The annotation there is also on the variable itself, instead of a member of the object.

@mhegazy mhegazy added Domain: JSDoc Relates to JSDoc parsing and type generation Salsa labels Apr 21, 2017
@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 21, 2017
@mhegazy mhegazy added this to the TypeScript 2.4 milestone Apr 21, 2017
@mhegazy mhegazy assigned rbuckton and unassigned sandersn May 11, 2017
@mhegazy mhegazy assigned yuit and unassigned rbuckton May 23, 2017
@yuit yuit added the Fixed A PR has been merged for this issue label May 31, 2017
yuit added a commit that referenced this issue Jun 22, 2017
[Master] Fix #13306 recognize @type on property assignment
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

6 participants