Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
TPreece
New Member

Custom object boolean problem

Dear Community,

 

I am currently having an issue with compiling a custom visual. I have intorduced a custom object (myCustomObj) with a boolean property (myprop). I am following the tutorial here: https://blogs.msdn.microsoft.com/tsmatsuz/2016/09/27/power-bi-custom-visuals-programming/

 

I am getting the error "TYPESCRIPT /src/visual.ts : (44,13) Type 'string | number | boolean | Date | Fill | FillRule | ISemanticFilter | DefaultValueDefinition | I...' is not assignable to type 'boo
lean'.
Type 'string' is not assignable to type 'boolean'." 

 

I have no idea what the issue could be, it says there is an error with the following line in my update function:

this.myVisualProp = options.dataViews[0].metadata.objects["myCustomObj"]["myprop"];

 

Yet when I put in a debugger and tried typeof(options.dataViews[0].metadata.objects["myCustomObj"]["myprop"]) in the console it returned "boolean". If I am doing something wrong please let me know, my full code is below: visual.ts, capabilities.json

 

module powerbi.extensibility.visual {

    export class Visual implements IVisual {
        private target: HTMLElement;
        private myVisualProp: boolean;

        constructor(options: VisualConstructorOptions) {
            var captionArea = document.createElement("div");
            captionArea.innerHTML = "This is a test chart";
            options.element.appendChild(captionArea);
            this.target = document.createElement("div");
            options.element.appendChild(this.target);

            this.myVisualProp = false;
        }

        public update(options: VisualUpdateOptions) {
            this.myVisualProp = options.dataViews[0].metadata.objects["myCustomObj"]["myprop"];
            this.target.innerHTML =
                "Custom Prop is " + this.myVisualProp;
                
        }

        public enumerateObjectInstances(options: EnumerateVisualObjectInstancesOptions): VisualObjectInstanceEnumeration {
            let objectName = options.objectName;
            let objectEnumeration: VisualObjectInstance[] = [];

            switch (objectName) {
                case 'myCustomObj':
                    objectEnumeration.push({
                        objectName: objectName,
                        properties: {
                            myprop: this.myVisualProp,
                        },
                        selector: null
                    });
                    break;
            };

            return objectEnumeration;
        }

        public destroy(): void {
            //TODO: perform any cleanup tasks here 
        }
    }
}
{
    "dataRoles": [
        {
            "displayName": "Category Data",
            "name": "category",
            "kind": "Grouping"
        },
        {
            "displayName": "Measure Data",
            "name": "measure",
            "kind": "Measure"
        },
        {
            "displayName": "Grouping",
            "name": "myGroup",
            "kind": "Grouping"
        }
    ],
    "dataViewMappings": [
        {
            "table": {
                "rows": {
                    "select": [
                        {"for": {"in": "myCategory"}},
                        {"for": {"in": "measure"}}
                    ]
                }
            }
        }
    ],
    "objects": {
    "myCustomObj": {
      "displayName": "Test Object",
      "properties": {
        "myprop": {
          "displayName": "Test Property",
          "type": { "bool": true }
                }
            }
        }
    }
}
1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@TPreece,

 

You may add Type assertions to workaround this issue.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@TPreece,

 

You may add Type assertions to workaround this issue.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors