Skip to content

Allow JSDoc casts of parenthesized expressions in JS#17211

Closed
weswigham wants to merge 10 commits intoparse-jsdoc-with-ts-type-parserfrom
use-jsdoc-casts
Closed

Allow JSDoc casts of parenthesized expressions in JS#17211
weswigham wants to merge 10 commits intoparse-jsdoc-with-ts-type-parserfrom
use-jsdoc-casts

Conversation

@weswigham
Copy link
Copy Markdown
Member

Fixes #5158

Based on #17176, since that changes some of the machinery that could have affected this.

Copy link
Copy Markdown
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, although I have one question and two nits before you merge.

Comment thread src/compiler/checker.ts

function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
if (isInJavaScriptFile(node)) {
if (node.jsDoc) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not combine these predicates?

Comment thread src/compiler/checker.ts
function checkParenthesizedExpression(node: ParenthesizedExpression, checkMode?: CheckMode): Type {
if (isInJavaScriptFile(node)) {
if (node.jsDoc) {
const typecasts = flatten<JSDocTag>(map(node.jsDoc, doc => filter(doc.tags, tag => tag.kind === SyntaxKind.JSDocTypeTag)));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you use flatMap instead? filter should always return an array so you don't need the if (isArray ... check in flatten.


class SomeBase {
constructor() {
this.p = 42;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests cases don't have type annotations. But based on your follow-up comment in the associated bug, the syntax

/** @type {number} */
this.p = 42;

should also work. I just want to confirm that this is not addressed in this PR.

sandersn and others added 9 commits July 17, 2017 08:41
* Minor cleanups in builder

* Use enumerateInsertsAndDeletes
… ones (#17179)

* Reuse stored types for any[] and Promise<any> instead of creating new ones

* Don't store anyPromiseType
`readFile` may return undefined
* Issue template: Recommand to run `tsc` directly

* List some common build tools
@weswigham
Copy link
Copy Markdown
Member Author

I'll reopen this against master (with feedback integrated) shortly.

@weswigham weswigham closed this Jul 17, 2017
weswigham added a commit that referenced this pull request Jul 17, 2017
@weswigham weswigham mentioned this pull request Jul 17, 2017
weswigham added a commit that referenced this pull request Jul 18, 2017
* Allow jsdoc casts of parenthesized expressions

* Feedback from #17211
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants