Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geometry creation in TypeScript #8941

Merged
merged 2 commits into from
Jun 10, 2020
Merged

Fix geometry creation in TypeScript #8941

merged 2 commits into from
Jun 10, 2020

Conversation

mramato
Copy link
Contributor

@mramato mramato commented Jun 9, 2020

None of the XXXGeometry classes are actually Geometry instances. They are instead utility classes that create geometries via their createGeometry implementation. GeometryInstance can take either "type" but since JS doesn't have types we never really defined what the "utility" type is, so the TypeScript definition for GeometryInstance specifies that currently only specifies Geometry. This means that this valid JS code is a compiler error in TypeScript

const geometryInstance = new GeometryInstance({
  geometry: new PolylineGeometry({
    positions: [],
  }),
});

To fix this, I introduced a GeometryFactory base class like we have elsewhere in the code and changed GeometryInstance to take either type. This is the only place where we actually base "non-geometry Geometry" in the API.

Happy to consider other names, like GeometryCreator if we don't like factory for some reason, but I want to get this in sooner rather than later for 1.70.1 fixes.

Also fixed an issue with tsconfig.json I introduced in my last change which was failing to actually catch TS compile errors because it wasn't including the Cesium.d.ts.

None of the `XXXGeometry` classes are actually `Geometry` instances. They
are instead utility classes that create geometries via their
`createGeometry` implementation. `GeometryInstance` can take either "type"
but since JS doesn't have types we never really defined what the "utility"
type is, so the TypeScript definition for `GeometryInstance` specifies that
currently only specifies `Geometry`. This means that this valid JS code
is a compiler error in TypeScript

```
const geometryInstance = new GeometryInstance({
  geometry: new PolylineGeometry({
    positions: [],
  }),
});
```

To fix this, I introduced a `GeometryFactory` base class like we have
elsewhere in the code and changed `GeometryInstance` to take either type.
This is the only place where we actually base "non-geometry Geometry" in
the API.

Happy to consider other names, like `GeometryCreator` if we don't like
factory for some reason, but I want to get this in sooner rather than
later for 1.70.1 fixes.

Also fixed an issue with tsconfig.json I introduced in my last change
which was failing to actually catch TS compile errors because it wasn't
including the Cesium.d.ts.
@cesium-concierge
Copy link

Thanks for the pull request @mramato!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.
  • Works (or fails gracefully) in IE11.

@mramato
Copy link
Contributor Author

mramato commented Jun 9, 2020

Fixes #8924

@mramato
Copy link
Contributor Author

mramato commented Jun 9, 2020

Not sure why travis thinks those builds are pending, it's pretty clear if you click on Details that they completed successfuly.

@kring kring merged commit dce2bef into master Jun 10, 2020
@kring kring deleted the ts-geometry branch June 10, 2020 00:53
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.

3 participants