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

Void method in if clause #10942

Closed
sant123 opened this issue Sep 15, 2016 · 4 comments
Closed

Void method in if clause #10942

sant123 opened this issue Sep 15, 2016 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@sant123
Copy link

sant123 commented Sep 15, 2016

TypeScript Version: 1.8.0

Is it a bug?

Code

class fsClass {
    exists(path: string, cb?: (exists: boolean) => void): void {

    }
}

var fs = new fsClass();

if(fs.exists("")){

}

Expected behavior:
Raise an error telling a void type is not permitted.

Actual behavior:
No error.

@RyanCavanaugh
Copy link
Member

We currently consider anything to be coercable to truthy/falsy. Might be dangerous in this case.

Really seems like your callback parameter should not be optional there, though.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Sep 15, 2016
@sant123
Copy link
Author

sant123 commented Sep 15, 2016

Thank you @RyanCavanaugh for your answer, well... that is an abstraction of the exists method from fs module of Node.js typing. I just noticed it when I was coding...

@jeffreymorlan
Copy link
Contributor

#7256

@RyanCavanaugh
Copy link
Member

Thanks @jeffreymorlan !

@RyanCavanaugh RyanCavanaugh added Duplicate An existing issue was already created and removed In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Sep 16, 2016
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants