I hope a TypeScript question is okay here.
It is my understanding that Cesium has provided type definitions in support of TS since release 1.70. I just haven’t seen how to use them. Can anyone point me to these directions (or push me in the right direction)?
Thanks!
Hi there,
Based on CesiumJS Adds Official TypeScript Type Definitions – Cesium, these are the setup instructions
We make use of the types field in package.json so no additional configuration is required in most cases. However, if you import individual CesiumJS source files directly, you’ll need to add “types”: [“cesium”] to your tsconfig.json in order for the definitions to be picked up. If you were previously using @types/cesium, you can remove it.
If you’re seeing something different, please let us know more about your config so we can help troubleshoot.
Thanks!
Gabby
1 Like
Hy Gabby,
Thanks so much for getting back to me - it’s really appreciated.
Sorry, I’m not quite sure what you are looking for in terms of configuration
Cesium, Angular, and TS were all installed fresh within the past two months
Let me know if there is something you are looking for in my config
Thanks very much for your time!
Ian
//Here's my approach with comments on what I'm seeing and wondering about...
//Setting up a simple ellipse
let eg = new Cesium.EllipseGraphics({semiMajorAxis: 1000, semiMinorAxis:500});
let e = new Cesium.Entity({
position: Cesium.Cartesian3.fromDegrees(-69.0, 39.0),
ellipse: eg
});
//The following line gives the following error
//Type 'number' is not assignable to type 'Property'.ts(2322)
//(property) EllipseGraphics.semiMajorAxis: Cesium.Property | undefined
eg.semiMajorAxis = 2000;
//This works, but do I have it right? Are there any concerns about garbage collection here?
eg.semiMajorAxis = new Cesium.ConstantProperty(2000);
//Similar to above
e.position = Cesium.Cartesian3.fromDegrees(-69.0, 40.0);
e.position = new Cesium.ConstantPositionProperty(Cesium.Cartesian3.fromDegrees(-69.0, 40.0));
Hi Gabby,
Please hold off on this question - I am making some progress on my end and don’t want to waste your time. Thanks very much!
Hey @imitchell
In case you have not find a solution yet, you need to add the cesium
types in your tsconfig.app.json
file such as:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": [
"cesium"
]
},
"files": [
"src/main.ts"
],
"include": [
"src/**/*.d.ts"
]
}
1 Like