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

Suggestion: Add support for jsdoc-based prefix cast syntax for JavaScript files #16345

Closed
rbuckton opened this issue Jun 8, 2017 · 2 comments
Assignees
Labels
Duplicate An existing issue was already created Suggestion An idea for TypeScript

Comments

@rbuckton
Copy link
Member

rbuckton commented Jun 8, 2017

Original discussion

This suggestion proposes we allow a new prefix cast syntax using /** @type {...} */ , e.g.:

// @ts-check

const map = new Map((/** @type {Array<[string, {x?:number, y?:number}]>} */[
    ['a', {x: 1}],
    ['b', {y: 2}]
]));

This syntax requires the expression to cast must be enclosed in parenthesis, and the jsdoc comment must be the first comment inside of the parenthesis. This is because it would be fairly expensive (in terms of both time and storage) to scan for jsdoc comments for every expression. This restriction would allow us to significantly reduce the overhead necessary to support this feature.

@evmar
Copy link
Contributor

evmar commented Jun 16, 2017

FWIW, in Closure code the cast syntax requires parens:

/** @type {Foo} */ (bar)

and they also allow a shorthand:

/** Foo */ (bar)

(Though of course the Closure type system is incompatible with the TS one so it's unlikely people will mix the two.)

@DanielRosenwasser
Copy link
Member

Duplicate of #5158?

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Jul 12, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 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 Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants