Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Address PR comments
  • Loading branch information
sandersn committed Mar 13, 2018
commit 7cb96ee6dd9ec9d041418d29fbf9f78a424c61e9
8 changes: 3 additions & 5 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4167,11 +4167,9 @@ namespace ts {

let isOptional = false;
if (includeOptionality) {
if (isInJavaScriptFile(declaration) && isParameterDeclaration(declaration)) {
const parameterTags = getJSDocParameterTags(declaration as ParameterDeclaration);
if (parameterTags && parameterTags.length > 0 && find(parameterTags, tag => tag.isBracketed)) {
isOptional = true;
}
if (isInJavaScriptFile(declaration) && isParameter(declaration)) {
const parameterTags = getJSDocParameterTags(declaration);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cast not valid, isParameterDeclaration returns true for non-parameters (maybe the name could use an improvement).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, isParameter isn't obvious since it's one of the few types that don't match the name of their syntax kind.

isOptional = !!(parameterTags && parameterTags.length > 0 && find(parameterTags, tag => tag.isBracketed));

@ghost Deleted user (ghost) Mar 13, 2018 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Simpler to write isOptional = ... than if (...) isOptional = true;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess so. Doesn't match the next branch, so it makes the code a little less obvious to read.

}
if (!isBindingElement(declaration) && !isVariableDeclaration(declaration) && !!declaration.questionToken) {
isOptional = true;
Expand Down