JamesLMilner / terra-draw

A library for drawing on maps that supports Mapbox, MapLibre, Google Maps, OpenLayers and Leaflet out the box
https://terradraw.io
MIT License
472 stars 55 forks source link

[Bug] Library not usable without skipLibCheck: true? #350

Open neodescis opened 5 days ago

neodescis commented 5 days ago

Describe the bug It seems that I cannot build a TypeScript project that references terra-draw without skipLibCheck enabled in my project. Without that, I get a bunch of TypeScript compilation errors. Here's a sampling:

node_modules/terra-draw/dist/extend.d.ts:1:57 - error TS2307: Cannot find module './adapters/common/base.adapter' or its corresponding type declarations.

1 import { TerraDrawBaseAdapter, BaseAdapterConfig } from "./adapters/common/base.adapter";
node_modules/terra-draw/dist/adapters/google-maps.adapter.d.ts:6:14 - error TS2503: Cannot find namespace 'google'.

6         map: google.maps.Map;
node_modules/terra-draw/dist/adapters/arcgis-maps-sdk.adapter.d.ts:7:27 - error TS2307: Cannot find module '@arcgis/core/layers/GraphicsLayer' or its corresponding type declarations.

7 import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";

The first error seems to be from referencing a file that isn't provided in the npm bundle (I do not see a common folder, or base.adapter.d.ts anywhere). I'm not sure why that file isn't included?

The other errors appear to come from not having various things installed to support the various adapters. However, I definitely do not want to install OpenLayers and others when I only care about MapLibre. One way something like this is generally solved is to move each adapter into its own npm package to separate out the dependencies.

Terra Draw npm version 1.0.0-beta.6

To Reproduce Steps to reproduce the behavior:

  1. Create TypeScript project without skipLibCheck: true
  2. Install and import terra-draw
  3. Build

Expected behavior No build errors!

Additional context Requiring skipLibCheck: true is onerous, and enabling it would not be doable in my project, where I have numerous internal dependencies that I would definitely like to get type-checked.

JamesLMilner commented 5 days ago

Hey @neodescis - thanks for raising this, sorry to hear it's causing you problems. To my understanding you shouldn't need skipLibCheck: true when using Terra Draw. I have just disabled it on two of projects that use Terra Draw directly with 1.0.0-beta.6:

https://github.com/JamesLMilner/terra-draw-route-snap-mode https://github.com/JamesLMilner/terra-draw-website

And I was not able to see any build errors. Are you able to share the repository with me if it's open source? If not potentially a minimal reproducible example? I would be interested to learn more and want to try and resolve this for you.

neodescis commented 5 days ago

I cannot share my repo, but I was able to recreate it on StackBlitz easily enough. I went with Angular as that's what we're using.

https://stackblitz.com/edit/stackblitz-starters-i6yevv?file=src%2Fapp%2Fapp.component.ts

One thought that jumps to mind is that Angular is shifting to esbuild, which may be a piece to the puzzle. The example above and our project are both using it.

I also went through and verified that all of the tsconfig settings are the same as for our project.

neodescis commented 4 days ago

Did this get auto-closed on accident? Your change is good, but the third-party references are still an issue. I've updated the StackBlitz to beta 7.

JamesLMilner commented 3 days ago

Hey @neodescis, yes it did, if you put an issue in the PR it seems to close it automatically. As you say this initially only resolves the internal issues. Resolving the external dependency issues is harder but I am exploring options for doing that.

JamesLMilner commented 3 days ago

Funnily in trying to reproduce this I actually hit my own issues trying to compile just MapLibre GL with tsc without skipLibCheck. I filed it here https://github.com/maplibre/maplibre-gl-js/issues/4855

Not strictly related to this issue but thought I'd share as has been a bit of a stumbling block for me testing locally.