cesium icon indicating copy to clipboard operation
cesium copied to clipboard

Incorrect type for terrain provider

Open dylantf opened this issue 3 weeks ago • 1 comments

What happened?

The TypeScript type for the terrainProvider property on the viewer, scene, and globe instances all indicates that it is a TerrainProvider, however in some cases it is undefined, as terrain appears to be loaded asynchronously and the property is set to undefined during this time. This can cause runtime errors if we believe the type that it is never undefined.

Reproduction steps

  1. Mount a Cesium viewer with terrain specified
  2. Log viewer.scene.terrainProvider

Sandcastle example

https://sandcastle.cesium.com/#c=jZBRS8MwFIX/yqVPrZQUX7e2CMMHYaDg0Je8ZMndFrxNRpJ2TPG/2zYtOJXh4z35zrknVzdH6wLcgPCwQq/bBnbONsATOU48WXLDjbTGB+g0ntBBBQZPE81eRi2d+ZU1QWiDjic5fHADENC5XlnMhk2c2bDm1TpSk5BmOTef2TIus4SM7L7PfTA6aEFzDhyd7bRCtxg2xEbMSzTIJuJpArKx+TVidRBmj4oJpe47NGGtfegxl6YZVHWsf1lm86MEyBjxrzLj55I8KX04E9ZD+p2O928dpYwVAZsjiYC+2LbyDQOT3g+mspgtpdIdaFX9cW+QJLzvX3Yt0bN+R57UZdHzFzayQmmzf+zQkTgPyOG2XkeRMVYW/fjbFaylrXDfEr8A

Environment

Browser: Chrome CesiumJS Version: 1.136.0 Operating System: Linux/Fedora 43

dylantf avatar Dec 02 '25 08:12 dylantf

This looks like a specific instance of https://github.com/CesiumGS/cesium/issues/11749#issuecomment-1950184016

It's OK to track this in a dedicated issue. The approach that is mentioned there (i.e. a regex-based search that allows finding many more of these cases, and simply adding | undefined to all these cases to fix them) should probably be applied in a "big bang cleanup" at some point.

javagl avatar Dec 02 '25 15:12 javagl