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

Update more return types to include undefined #15903

Merged
merged 4 commits into from
May 23, 2017

Conversation

ajafff
Copy link
Contributor

@ajafff ajafff commented May 17, 2017

This PR updates even more return types where undefined can be returned.
The changes in services.ts and jsdoc.ts are not strictly necessary, because the APIs defined there are not public. But it may help you when you want to enable strictNullChecks in this project.

Ref: #15887

@@ -19,34 +19,34 @@ namespace ts {
getFirstToken(sourceFile?: SourceFile): Node;
getLastToken(sourceFile?: SourceFile): Node;
// See ts.forEachChild for documentation.
forEachChild<T>(cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T;
forEachChild<T>(cbNode: (node: Node) => T, cbNodeArray?: (nodes: Node[]) => T): T | undefined;
Copy link

Choose a reason for hiding this comment

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

Callbacks should also return | undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@andy-ms
T is inferred from the return type of the callback(s). I don't get why it should be declared to return T | undefined. Can you please explain your thoughts on this?

Copy link

Choose a reason for hiding this comment

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

Just for documentation: if a callback always returns a truthy value then forEachChild will terminate immediately and return the first result. Since it's always allowed to return undefined, it doesn't hurt to have it there explicitly.

@DickvdBrink
Copy link
Contributor

Looks like there is something wrong with the line-endings in checkter.ts - notice the ^M in the diff

@ajafff
Copy link
Contributor Author

ajafff commented May 18, 2017

@DickvdBrink that seems to be an issue with github. Other PRs also have this ^M although the files are consistently using CRLF

@DickvdBrink
Copy link
Contributor

Ah oke, my bad ;) 👍

@mhegazy
Copy link
Contributor

mhegazy commented May 22, 2017

@andy-ms any more comments?

@mhegazy
Copy link
Contributor

mhegazy commented May 23, 2017

@ajafff mind updating the PR.

@ajafff
Copy link
Contributor Author

ajafff commented May 23, 2017

@mhegazy @andy-ms updated and resolved conflicts.

@mhegazy mhegazy merged commit f8aae89 into microsoft:master May 23, 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants