Skip to content

Void method in if clause #10942

Closed
Closed

Description

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.

Activity

  1. RyanCavanaugh commented on Sep 15, 2016

    @RyanCavanaugh
    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.

  2. sant123 commented on Sep 15, 2016

    @sant123
    Author

    Thank you Ryan Cavanaugh (@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...

  3. jeffreymorlan commented on Sep 16, 2016

    @jeffreymorlan
    Contributor
  4. RyanCavanaugh commented on Sep 16, 2016

    @RyanCavanaugh
    Member

    Thanks jeffreymorlan !

  5. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions