Optional boolean parameter comes in as an Object in TypeScript constructor

47 Views Asked by At

As the title says. I have the following constructor in a TypeScript class. This is within Serenity framework.

constructor(private isAllRequest?: boolean) {
    super();
    // initialise grids
    this.requestAbsenceInteractionGrid = new RequestAbsenceInteractionGrid(this.byId("RequestAbsenceInteractionGrid"));
    this.requestAbsenceDocumentGrid = new RequestAbsenceDocumentGrid(this.byId("RequestAbsenceDocumentGrid"));
    this.requestLogGrid = new RequestLogGrid(this.byId("RequestLogGrid"));

    if (isAllRequest) {
        this.fromAllRequest = isAllRequest;
    }
}

Instead of a boolean, I get the following:

enter image description here

This is obviously troublesome because doing an if on an empty object always returns true. I need that param to be a boolean, and it should be, but I don't know why it isn't.

If I do the following:

if (typeof isAllRequest === 'boolean' && isAllRequest) {
    this.fromAllRequest = isAllRequest;
}

Then I get the expected behaviour, but I'm confused why that's necessary. I'm telling TypeScript that the param is of type boolean.

How is that constructor called?

The constructor which sits on a dialog class is opened via a link like so: link to open serenity dialog

Could it be that Serenity by default passes in an object?

0

There are 0 best solutions below