rbrundritt/maplibre-gl-svg

Typescript check fails

Closed this issue · 1 comments

Hi, I am trying to use this library to render svg images with maplibre inside a React application, however i am getting an error when i try to build using vite alongside with typescript checks:

node_modules/maplibre-gl-svg/src/SvgManager.ts:69:20 - error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

69                 if(map._requestManager._transformRequestFn) {
                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in node_modules/maplibre-gl-svg/src/SvgManager.ts:69

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This happens whenever you run tsc on a project that imports SvgManager as follows:

import { SvgManager } from "maplibre-gl-svg/src";


const App = () => {

  return <></>;
}

And this is how I define the dependency on my package.json:

    "dependencies": {
        ...
        "maplibre-gl-svg": "git+https://github.com/rbrundritt/maplibre-gl-svg.git",
       ...
    },

The version of typescript being used is:

tsc --version     
Version 4.6.4

Maybe there is something I need to configure that I am not aware of? Any feedback is appreciated 😃

Sounds like you have some very strict rules in your typescript environment as this is not an error/bug, but is perfectly acceptable code. The reason for this check is that the _requestManager is an undocumented feature of the map SDK which means it could be removed in the future, so this if statement does a check to make sure it's still available so it can use it or failover gracefully.To handle this you can modify your typescript compiling rules to disable strictNullChecks. Since the _requestManager function is defined externally, this project can't change this to a nullable type which make the compiler happy.

I'm not sure if it would help, but a ``//@ts-ignore` could be added above this line of code. I'm note sure if the typescript compiler would ignore this or not, or if this will only get rid of any syntax highlighting that might appear.