Skip to content

Typescript errors when setting color properties of various Cesium objects #9667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
markchagers opened this issue Jul 8, 2021 · 3 comments

Comments

@markchagers
Copy link

When setting a color-property (color, fillColor, outlineColor, etc) of an instance of a Cesium object, the typescript definitions don't seem to match the actual implementation in CesiumJS.
For instance, if I try to set the fillColor of a LabelGraphics object:

labelGraphics.fillColor = Cesium.Color.PURPLE

typescript errors occur when setting the property to a Cesium.Color directly. Wrapping the Color in a ColorMaterialProperty:

labelGraphics.fillColor = new ColorMaterialProperty(Cesium.Color.PURPLE)

this silences the typescript error, but the color isn't applied during runtime.
If I ignore the typescript error and set the color directly it does work, but then the typescript errors interfere with my normal development process.

Sandcastle example:
AFAIK there is no option to use typescript in sandcastle, so it's not possible to repro this issue there.
Browser: Any

Operating System: MacOS (not likely to have a bearing on this)

Looking at the typescript definitions in node_modules/cesium/Source/Cesium.d.ts, I see at line 21534:

fillColor: Property | undefined;

If I change this to:

fillColor: Color | Property | undefined;

this solves the problem, but it's debatable whether this is the proper solution or rather that the implementation in CesiumJS should be fixed to match the typescript definitions.

@jjspace
Copy link
Contributor

jjspace commented Jan 31, 2025

Also reported on the forums https://community.cesium.com/t/applying-a-new-style-stroke-color-to-a-geojson-polygon/38029/7

The solution Matt mentioned in this comment to use new ConstantProperty(Color.RED) instead of the color directly should work and make Typescript happy.

Longer term I think this is something that should be easier to address once #10455 and #8359 are addressed

@ggetz
Copy link
Contributor

ggetz commented Feb 3, 2025

CC #8930

@markchagers
Copy link
Author

markchagers commented Feb 6, 2025

I'm surprised this issue is still open. Back in 2020 I started work on a (pre-existing) large angular application that employs Cesium for mapping. The cesium dependency in that application was many releases behind at the time, and my first task was updating it which led to typescript errors that I thought should be solved by changing the jsdoc typings of some properties. I even made a pull request to that end (9673).
The suggestion by @mramato to wrap the color in a constantproperty was spot on however, and solved my issues, so I closed the PR, which was unnecessary.
I do concur that the documentation on this could be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants