ROU-12774: Fix TerraDraw dispose crash and TypeScript type errors #260
Merged
rugoncalves merged 12 commits intodevfrom Apr 27, 2026
Merged
ROU-12774: Fix TerraDraw dispose crash and TypeScript type errors #260rugoncalves merged 12 commits intodevfrom
rugoncalves merged 12 commits intodevfrom
Conversation
This rule is not relevant for our project, as this rule is intended to improve portability, consistency, and testing across different JavaScript environments (browsers, Web Workers, and Node.js).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses stability and TypeScript typing issues in the TerraDraw drawing tools integration and related provider code (deck.gl + Google Maps shapes), primarily by guarding teardown logic and aligning runtime-global access with the project’s Window type augmentation.
Changes:
- Switched runtime-global accesses from
globalThistowindowfor TerraDraw and deck.gl providers to satisfy existingWindowaugmentation typing. - Adjusted TerraDraw tool configuration typing (
getProviderConfig(): unknown) and updated mode constructors to use constructor-parameter-derived option types. - Fixed a Google Maps polygon typing mismatch by asserting the
pathstype, and added a SonarCloud suppression fortypescript:S7764.
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Providers/Maps/Google/Shape/Polygon.ts | Casts polygon paths to google.maps.LatLngLiteral[] to resolve TS mismatch. |
| src/Providers/Layers/deck.gl/HeatmapLayer.ts | Uses window.deck instead of globalThis.deck to align with Window typings. |
| src/Providers/DrawingTools/TerraDraw/Tools/DrawRectangle.ts | Uses window.terraDraw and constructor-parameter typing for mode options. |
| src/Providers/DrawingTools/TerraDraw/Tools/DrawPolyline.ts | Uses window.terraDraw and constructor-parameter typing for mode options. |
| src/Providers/DrawingTools/TerraDraw/Tools/DrawPolygon.ts | Uses window.terraDraw and constructor-parameter typing for mode options. |
| src/Providers/DrawingTools/TerraDraw/Tools/DrawMarker.ts | Uses window.terraDraw and constructor-parameter typing for mode options. |
| src/Providers/DrawingTools/TerraDraw/Tools/DrawCircle.ts | Uses window.terraDraw and constructor-parameter typing for mode options. |
| src/Providers/DrawingTools/TerraDraw/DrawingTools.ts | Adds an enabled guard in dispose() and swaps TerraDraw globals to window. |
| src/Providers/DrawingTools/TerraDraw/Configuration/DrawPolylineConfig.ts | Changes provider config return type to unknown and removes array casts. |
| src/Providers/DrawingTools/TerraDraw/Configuration/DrawMarkerConfig.ts | Changes provider config return type to unknown and removes array casts. |
| src/Providers/DrawingTools/TerraDraw/Configuration/DrawFilledShapeConfig.ts | Changes provider config return type to unknown and removes array casts. |
| src/Providers/DrawingTools/TerraDraw/Configuration/DrawConfig.ts | Updates abstract getProviderConfig() signature to return unknown. |
| sonar-project.properties | Adds project-wide Sonar ignore rule for typescript:S7764. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
joselrio
approved these changes
Apr 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This PR fixes a crash when disposing TerraDraw drawing tools that were never activated, and resolves several TypeScript compiler errors in the TerraDraw and deck.gl providers.
What was happening
dispose()was callingsetMode()andstop()unconditionally, but TerraDraw throws whenstop()is called on an instance that was never started (i.e.,enabledis false).globalThis.terraDraw,globalThis.terraDrawGoogleMapsAdapter, andglobalThis.deckcaused TS error 7017. Runtime-injected browser globals are declared viainterface Windowaugmentation inGlobal.d.ts, which TypeScript only resolves throughwindow, notglobalThis.DrawConfig.getProviderConfig()was typed asunknown[](array), but all implementations return a plain options object{ styles: { ... } }. Passingunknown[]to TerraDraw mode constructors triggered TS2559 ("Type 'unknown[]' has no properties in common with...") across all five Draw tool classes.Polygon._createProviderpassedpathasArray<Coordinates>wheregoogle.maps.LatLngLiteral[]was expected, causing a type mismatch.What was done
setMode()/stop()calls indispose()behind athis.provider.enabledcheck. If the drawing tool was built but the user never interacted with it, the TerraDraw instance is never started and must be skipped during teardown.globalThiswithwindowacross all TerraDraw (DrawingTools.ts, allDrawXxx.tstools) and deck.gl (HeatmapLayer.ts) provider files. Added a project-level SonarCloud suppression for ruletypescript:S7764insonar-project.properties— thewindowpattern is correct here given theWindowaugmentation strategy.DrawConfig.getProviderConfig()return type fromunknown[]tounknown. Removed theas unknown as unknown[]double-cast from all three config subclasses. Updated all fivecreateTerraDrawMode()callers to cast viaConstructorParameters<typeof window.terraDraw.TerraDrawXxxMode>[0], which derives the expected options type directly from the constructor signature.as google.maps.LatLngLiteral[]cast topathinPolygon._createProvider.Test Steps
Hide Drawing Tools error
Type errors
npm run buildcommandScreenshots
(prefer animated gif)
Checklist