Repository navigation
Types: Enable type checks in 'cesium/core' (pt3) - #14065
donmccurdy wants to merge 4 commits into
Conversation
|
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 |
There was a problem hiding this comment.
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.
| options = | ||
| options ?? | ||
| /** @type {BoxGeometryConstructorOptions} */ (Frozen.EMPTY_OBJECT); |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
| /** | ||
| * Utility function providing TypeScript's `keyof` behavior, which otherwise | ||
| * wouldn't be compatible with tsd-jsdoc. | ||
| */ | ||
| export type KeyOf<T> = keyof T; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| if (isFunctionLocal(doclet)) { | ||
| if (isFunctionLocal(doclet) || isInPrivateMember(doclet)) { |
There was a problem hiding this comment.
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;93e1227 to
0a8eb7b
Compare
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-tsandnpm run tsc, should pass.Result of
scripts/diff-types.sh:diff
Author checklist
CONTRIBUTORS.mdCHANGES.mdwith a short summary of my changeAI acknowledgment
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