Skip to content

Types: Enable type checks in 'cesium/core' (pt3) - #14065

Open
donmccurdy wants to merge 4 commits into
mainfrom
donmccurdy/types/core-pt3
Open

donmccurdy wants to merge 4 commits into
mainfrom
donmccurdy/types/core-pt3

Conversation

@donmccurdy

@donmccurdy donmccurdy commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Description

Enables type checking for Geometry and BoxGeometry. The decisions here weren't quite as straightforward as those in #14064, so I've split this into a separate PR affecting just a couple files.

Issue number and link

Testing plan

CI, which includes npm run build-ts and npm run tsc, should pass.

Result of scripts/diff-types.sh:

diff
diff --git a/Source/Cesium.main.d.ts b/Source/Cesium.d.ts
index 1e4002c786..fc4eacacfc 100644
--- a/Source/Cesium.main.d.ts
+++ b/Source/Cesium.d.ts
@@ -782,6 +782,28 @@ export class BoundingSphere {
     static packedLength: number;
 }
 
+/**
+ * @property minimum - The minimum x, y, and z coordinates of the box.
+ * @property maximum - The maximum x, y, and z coordinates of the box.
+ * @property [vertexFormat = VertexFormat.DEFAULT] - The vertex attributes to be computed.
+ */
+export type BoxGeometryConstructorOptions = {
+    minimum: Cartesian3;
+    maximum: Cartesian3;
+    vertexFormat?: VertexFormat;
+    offsetAttribute?: GeometryOffsetAttribute;
+};
+
+/**
+ * @property dimensions - The width, depth, and height of the box stored in the x, y, and z coordinates of the <code>Cartesian3</code>, respectively.
+ * @property [vertexFormat = VertexFormat.DEFAULT] - The vertex attributes to be computed.
+ */
+export type BoxGeometryFromDimensionsOptions = {
+    dimensions: Cartesian3;
+    vertexFormat?: VertexFormat;
+    offsetAttribute?: GeometryOffsetAttribute;
+};
+
 /**
  * Describes a cube centered at the origin.
  * @example
@@ -791,17 +813,9 @@ export class BoundingSphere {
  *   minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0)
  * });
  * const geometry = Cesium.BoxGeometry.createGeometry(box);
- * @param options - Object with the following properties:
- * @param options.minimum - The minimum x, y, and z coordinates of the box.
- * @param options.maximum - The maximum x, y, and z coordinates of the box.
- * @param [options.vertexFormat = VertexFormat.DEFAULT] - The vertex attributes to be computed.
  */
 export class BoxGeometry {
-    constructor(options: {
-        minimum: Cartesian3;
-        maximum: Cartesian3;
-        vertexFormat?: VertexFormat;
-    });
+    constructor(options?: BoxGeometryConstructorOptions);
     /**
      * Creates a cube centered at the origin given its dimensions.
      * @example
@@ -810,14 +824,8 @@ export class BoxGeometry {
      *   dimensions : new Cesium.Cartesian3(500000.0, 500000.0, 500000.0)
      * });
      * const geometry = Cesium.BoxGeometry.createGeometry(box);
-     * @param options - Object with the following properties:
-     * @param options.dimensions - The width, depth, and height of the box stored in the x, y, and z coordinates of the <code>Cartesian3</code>, respectively.
-     * @param [options.vertexFormat = VertexFormat.DEFAULT] - The vertex attributes to be computed.
      */
-    static fromDimensions(options: {
-        dimensions: Cartesian3;
-        vertexFormat?: VertexFormat;
-    }): BoxGeometry;
+    static fromDimensions(options?: BoxGeometryFromDimensionsOptions): BoxGeometry;
     /**
      * Creates a cube from the dimensions of an AxisAlignedBoundingBox.
      * @example
@@ -5549,6 +5557,25 @@ export class GeographicProjection implements MapProjection {
     unproject(cartesian: Cartesian3, result?: Cartographic): Cartographic;
 }
 
+/**
+ * @property attributes - Attributes, which make up the geometry's vertices.
+ * @property [primitiveType = PrimitiveType.TRIANGLES] - The type of primitives in the geometry.
+ * @property [indices] - Optional index data that determines the primitives in the geometry.
+ * @property [boundingSphere] - An optional bounding sphere that fully enclosed the geometry.
+ * @property [boundingSphereCV] - Internal.
+ * @property [geometryType] - Internal.
+ * @property [offsetAttribute] - Internal.
+ */
+export type GeometryConstructorOptions = {
+    attributes: GeometryAttributes;
+    primitiveType?: PrimitiveType;
+    indices?: Uint16Array | Uint32Array;
+    boundingSphere?: BoundingSphere;
+    boundingSphereCV?: BoundingSphere;
+    geometryType?: unknown;
+    offsetAttribute?: GeometryOffsetAttribute;
+};
+
 /**
  * A geometry representation with attributes forming vertices and optional index data
  * defining primitives.  Geometries and an {@link Appearance}, which describes the shading,
@@ -5577,19 +5604,9 @@ export class GeographicProjection implements MapProjection {
  *   primitiveType : Cesium.PrimitiveType.LINES,
  *   boundingSphere : Cesium.BoundingSphere.fromVertices(positions)
  * });
- * @param options - Object with the following properties:
- * @param options.attributes - Attributes, which make up the geometry's vertices.
- * @param [options.primitiveType = PrimitiveType.TRIANGLES] - The type of primitives in the geometry.
- * @param [options.indices] - Optional index data that determines the primitives in the geometry.
- * @param [options.boundingSphere] - An optional bounding sphere that fully enclosed the geometry.
  */
 export class Geometry {
-    constructor(options: {
-        attributes: GeometryAttributes;
-        primitiveType?: PrimitiveType;
-        indices?: Uint16Array | Uint32Array;
-        boundingSphere?: BoundingSphere;
-    });
+    constructor(options?: GeometryConstructorOptions);
     /**
      * Attributes, which make up the geometry's vertices.  Each property in this object corresponds to a
      * {@link GeometryAttribute} containing the attribute's data.
@@ -5632,7 +5649,7 @@ export class Geometry {
      * Optional index data that - along with {@link Geometry#primitiveType} -
      * determines the primitives in the geometry.
      */
-    indices: any[] | undefined;
+    indices: Uint16Array | Uint32Array | undefined;
     /**
      * The type of primitives in the geometry.  This is most often {@link PrimitiveType.TRIANGLES},
      * but can varying based on the specific geometry.

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

AI acknowledgment

  • I used AI to generate content in this PR
  • If yes, I have reviewed the AI-generated content before submitting

If yes, I used the following Tools(s) and/or Service(s):

GitHub Copilot

If yes, I used the following Model(s):

Claude Opus 5.5

PR Dependency Tree

This tree was auto-generated by Charcoal

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for the pull request, @donmccurdy!

✅ We can confirm we have a CLA on file for you.

/** @import AxisAlignedBoundingBox from "./AxisAlignedBoundingBox.js"; */

/**
* @typedef {object} BoxGeometryConstructorOptions

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the constructor @param tags to a standalone FooGeometryConstructorOptions typedef, so that we can reference the types later:

options ??= /** @type {BoxGeometryConstructorOptions} */ (Frozen.EMPTY_OBJECT);

While I considered putting the typedefs under a namespace (e.g. BoxGeometry.ConstructorOptions, BoxGeometry.FromDimensionsOptions) that runs into trouble with #13903.

Comment on lines +56 to +58
options =
options ??
/** @type {BoxGeometryConstructorOptions} */ (Frozen.EMPTY_OBJECT);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small lie, but one that TypeScript allows. If we wanted the type checker to understand that required properties of BoxGeometryConstructorOptions might now be missing from the options object, we'd need to use a local variable...

/** @type {Partial<BoxGeometryConstructorOptions>} */
const partialOptions = options ?? Frozen.EMPTY_OBJECT;

... and be careful to use partialOptions for the remainder of the constructor. But this only improves type safety if strict mode is enabled, and that's not a current focus, so I think it's probably better to avoid a lot of unnecessary options-to-partialOptions renaming for now.

* @property {Uint16Array|Uint32Array} [indices] Optional index data that determines the primitives in the geometry.
* @property {BoundingSphere} [boundingSphere] An optional bounding sphere that fully enclosed the geometry.
* @property {BoundingSphere} [boundingSphereCV] Internal.
* @property {unknown} [geometryType] Internal.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using {unknown} instead of {GeometryType} here, because the GeometryType enum is currently tagged @private, and npm run build-ts fails if we reference it. Changing GeometryType to @internal doesn't resolve that error, because Geometry is exported from the top-level cesium package.

I'm not aware of any way to include private properties on a public typedef in JSDoc. The alternative would be to make GeometryType public, which might also be fine — I don't have any strong preference there.

Comment thread packages/core/Source/globalTypes.d.ts Outdated
Comment on lines +1 to +5
/**
* Utility function providing TypeScript's `keyof` behavior, which otherwise
* wouldn't be compatible with tsd-jsdoc.
*/
export type KeyOf<T> = keyof T;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small workaround to let us use keyof, by moving its use to a .d.ts file where it won't break tsd-jsdoc. The limitation is that KeyOf<Foo> cannot leak into any public/exported interfaces, but that's easy to catch because npm run build-ts will fail.

The main alternative I can see would be to use // @ts-expect-error instead, or cast to /** @type {*} */. I usually prefer to avoid * ("any"), as it tends to silently drop type safety elsewhere in the code.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were using tsc instead of tsd-jsdoc, would we need this workaround? Given this PR and #14064, how far are we from being able to switch the core package declarations to tsc, using the strategy of #14076?

If tsc would let us use keyof directly, but we're not ready to switch yet, maybe we will want an issue to track the tsd-jsdoc workarounds that can be removed when we do switch.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSDoc tooling doesn't recognize TypeScript syntax even once tsd-jsdoc is out of the picture, unfortunately, this came up with type intersections A & B. The workaround — now pulled into #14147, sorry I should have checked with you first! — does work for both jsdoc and tsd-jsdoc.

There might be other options too, though. For example I could imagine a jsdoc plugin that detects unsupported syntax and converts it to something JSDoc-friendly (e.g. keyof T -> KeyOf<T>) as a build step rather than a separate set of utility types contributors need to remember.

Comment thread packages/core/Source/BoxGeometry.js Resolved
Comment thread packages/core/Source/BoxGeometry.js Resolved
}

if (isFunctionLocal(doclet)) {
if (isFunctionLocal(doclet) || isInPrivateMember(doclet)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, type declarations inside private members would leak into the public global type definitions, found in ./scripts/diff-types.sh:

+export var options: BoxGeometryConstructorOptions;
+
+export var unitBoxGeometry: Geometry | undefined;

@donmccurdy
donmccurdy marked this pull request as ready for review November 19, 2026 09:09
@donmccurdy donmccurdy changed the title Types: Enable type checking for Geometry base class Types: Enable type checks in 'cesium/core' (pt3) Dec 4, 2026
@donmccurdy
donmccurdy force-pushed the donmccurdy/types/core-pt3 branch from 93e1227 to 0a8eb7b Compare December 4, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants