I get the error, when setting the skyAtmosphere in the viewer-options to false:
TS2345: Argument of type ‘{ requestRenderMode: boolean; maximumRenderTimeChange: number; homeButton: boolean; baseLayerPicker: boolean; fullscreenButton: boolean; sceneModePicker: boolean; infoBox: boolean; selectionIndicator: boolean; … 7 more …; skyAtmosphere: boolean; }’ is not assignable to parameter of type ‘ConstructorOptions’.
Types of property ‘skyAtmosphere’ are incompatible.
Type ‘boolean’ is not assignable to type ‘false | SkyAtmosphere | undefined’.
I think, that this can happen also on other definitions due that false is a boolean in typescript.
Thank you for providing some details on the error that you are receiving. Which other definitions are you seeing this behavior for? I suspect that this is more of a Typescript error than a CesiumJS error.
@Ruediger_Brand Strictly speaking a boolean is not assignable to a type false | SkyAtmosphere | undefined (which is a so-called composite type definition) since a boolean can also be true which is not part of this definition.
Are you trying to assign it the value of a (boolean) variable or are you using false explicitly?
If you could provide the line of your code where your issue occurs or a sandcastle example, that would give us some context.
Can you post a complete example? I use skyAtmosphere: false as an argument in Typescript without any issues – I’m not able to reproduce the error you’re getting.
The problem is with implicit typing. When Typescript infers the type of a variable from a literal you’re assigning to it, it treats literal property values as being their broader type – number literals become number, string literals become string, etc.
If you explicitly type const options3D: Viewer.ConstructorOptions = {...}, the error will be resolved. Alternately, you can write const options3D = { ... } as const;. This will create a readonly (frozen) object literal, and the type of options3D will use the individual values you specified instead of the wider primitive types.