Search code examples
typescriptpowerbipowerbi-custom-visualspowerbi-api

Same code leads to errors in different projects


I'm currently using the Power BI Visuals API to transfer my D3 chord diagram into a power bi visual. I've been using the Microsoft Chord GitHub Repo as a starting reference. I'm creating the supporting classes, but I'm getting errors returned in my version even when I use the same code from the microsoft repo.

Looking specifically at the 'columns.ts' file, when I copy the code as is from the github, I get errors on the 'let varName: type = x' lines saying that undefined cannot be assigned to DataViewTable type. But I cloned the entire repository from Microsoft, and I don't get those errors when I import their file directly.

Code is exactly the same. Cloned from GitHub Copied from GitHub to my project

I've tried adding try catch statements, if else checks, and I've also tried the non-null assertion operator where I can - but I still run into issues in the functions that return null. I just don't understand why the same code will provide errors in one location.


Solution

  • You may have strictNullChecks enabled in your tsconfig.json whereas it doesn't appear to be enabled in this repo's tsconfig.json.

    Note: This may also be listed as strict which enables strictNullChecks as well as a number of other strict type-checking flags

    If that is the case, their configuration will have looser type checking rules (when it comes to null/undefined checking) than yours, effectively allowing assignment of null or undefined to any other type, even if it is not explicitly stated in the type definition.

    Typescript Playgrounds:

    If this is the case, you have the option to:

    • Also disable strictNullChecks and accept the same loose typing rules
    • Modify your local typing of the variables in question to be more representative (i.e. include | null or | undefined in variable definitions that could/should handle those values)