CesiumGS / CesiumGS/cesium

Cartesian clone type definition is wrong

Open
#13,265 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

category - typescript type - bug type - regression
Dominant language
JavaScript
Stars
15.8k
Forks
3.9k
Avg merge
4d 6h
Merged PRs (30d)
34

Description

What happened?

After #13168, the generated TypeScript definitions for the static clone methods are incorrect. Methods are extended to accept undefined and return undefined in that case, but TypeScript will throw an error on this with skipLibCheck: false.

TS2322: Type 'undefined' is not assignable to type 'Cartesian3'.
    102 |   static clone(cartesian, result) {
    103 |     if (!defined(cartesian)) {
  > 104 |       return undefined;
        |       ^^^^^^
    105 |     }
    106 |     if (!defined(result)) {
    107 |       return new Cartesian3(cartesian.x, cartesian.y, cartesian.z);

https://github.com/CesiumGS/cesium/blob/2428f04ac54f896b975a4fe1b90319feb62e080a/packages/engine/Source/Core/Cartesian2.js#L58-L76

Reproduction steps
Sandcastle example

No response

Environment

CesiumJS Version: 1.139.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with packages/engine/Source/Core/Cartesian2.js around lines 58-76 and inspect how the static clone methods produce their generated TypeScript definitions. Run the TypeScript check with skipLibCheck set to false and confirm the clone definitions accept undefined and represent an undefined return without TS2322 errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.