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

Upgrade to TypeScript v4.9.4 and fix all the errors #6666

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Core/AbstractConstructor.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
type AbstractConstructor<T> = Function & { prototype: T };
type AbstractConstructor<T> = abstract new (...args: any[]) => T;
export default AbstractConstructor;
2 changes: 1 addition & 1 deletion lib/Map/Cesium/CesiumRenderLoopPauser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default class CesiumRenderLoopPauser {
if ("onwheel" in canvas) {
// spec event type
this._wheelEvent = "wheel";
} else if (defined(globalThis.onmousewheel)) {
} else if (defined((globalThis as any).onmousewheel)) {
// legacy event type
this._wheelEvent = "mousewheel";
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/Map/ImageryProvider/ProtomapsImageryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import booleanIntersects from "@turf/boolean-intersects";
import circle from "@turf/circle";
import { Feature } from "@turf/helpers";
import i18next from "i18next";
import { cloneDeep } from "lodash-es";
import { cloneDeep, isEmpty } from "lodash-es";
import { action, observable, runInAction } from "mobx";
import {
Bbox,
Expand Down Expand Up @@ -507,7 +507,7 @@ export default class ProtomapsImageryProvider
// Only create FeatureInfo for visible features with properties
if (
!f.feature.props ||
f.feature.props === {} ||
isEmpty(f.feature.props) ||
!renderedLayers.includes(f.layerName)
)
return;
Expand Down
6 changes: 3 additions & 3 deletions lib/ModelMixins/AccessControlMixin.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { action, computed, observable } from "mobx";
import Constructor from "../Core/Constructor";
import AbstractConstructor from "../Core/AbstractConstructor";
import Model, { BaseModel } from "../Models/Definition/Model";
import ModelTraits from "../Traits/ModelTraits";

type AccessControlModel = Model<ModelTraits>;

function AccessControlMixin<T extends Constructor<AccessControlModel>>(
function AccessControlMixin<T extends AbstractConstructor<AccessControlModel>>(
Base: T
) {
class Klass extends Base {
abstract class Klass extends Base {
@observable private _accessType: string | undefined;

get hasAccessControlMixin() {
Expand Down
6 changes: 2 additions & 4 deletions lib/ModelMixins/CatalogFunctionJobMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function CatalogFunctionJobMixin<
*
* @returns true for FINISHED, false for RUNNING (will then call pollForResults)
*/
protected abstract async _invoke(): Promise<boolean>;
protected abstract _invoke(): Promise<boolean>;

public async invoke() {
this.setTrait(CommonStrata.user, "jobStatus", "running");
Expand Down Expand Up @@ -245,9 +245,7 @@ function CatalogFunctionJobMixin<
* Called in {@link CatalogFunctionJobMixin#onJobFinish}
* @returns catalog members to add to workbench
*/
abstract async downloadResults(): Promise<
CatalogMemberMixin.Instance[] | void
>;
abstract downloadResults(): Promise<CatalogMemberMixin.Instance[] | void>;

@action
protected setOnError(error: unknown, raiseToUser: boolean = true) {
Expand Down
16 changes: 8 additions & 8 deletions lib/ModelMixins/CatalogMemberMixin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { action, computed, isObservableArray, runInAction, toJS } from "mobx";
import Mustache from "mustache";
import AbstractConstructor from "../Core/AbstractConstructor";
import AsyncLoader from "../Core/AsyncLoader";
import Constructor from "../Core/Constructor";
import isDefined from "../Core/isDefined";
import { isJsonObject, isJsonString, JsonObject } from "../Core/Json";
import Result from "../Core/Result";
Expand All @@ -21,7 +21,9 @@ import ReferenceMixin from "./ReferenceMixin";

type CatalogMember = Model<CatalogMemberTraits>;

function CatalogMemberMixin<T extends Constructor<CatalogMember>>(Base: T) {
function CatalogMemberMixin<T extends AbstractConstructor<CatalogMember>>(
Base: T
) {
abstract class CatalogMemberMixin
extends AccessControlMixin(Base)
implements SelectableDimensions, ViewingControls
Expand Down Expand Up @@ -98,14 +100,12 @@ function CatalogMemberMixin<T extends Constructor<CatalogMember>>(Base: T) {
return this.terria.workbench.contains(this);
}

@computed
get name(): string | undefined {
return super.name || this.uniqueId;
protected nameOverride(traitValue: string | undefined) {
return traitValue || this.uniqueId;
}

@computed
get nameInCatalog(): string | undefined {
return super.nameInCatalog || this.name;
protected nameInCatalogOverride(traitValue: string | undefined) {
return traitValue || this.name;
}

@computed
Expand Down
5 changes: 2 additions & 3 deletions lib/ModelMixins/Cesium3dTilesMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,11 @@ function Cesium3dTilesMixin<T extends Constructor<Model<Cesium3dTilesTraits>>>(
return [this.tileset, ...this.clippingMapItems];
}

@computed
get shortReport(): string | undefined {
protected shortReportOverride(traitValue: string | undefined) {
if (this.terria.currentViewer.type === "Leaflet") {
return i18next.t("models.commonModelErrors.3dTypeIn2dMode", this);
}
return super.shortReport;
return traitValue;
}

@computed get optionsObj() {
Expand Down
6 changes: 4 additions & 2 deletions lib/ModelMixins/ChartableMixin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { maxBy, minBy } from "lodash-es";
import Constructor from "../Core/Constructor";
import AbstractConstructor from "../Core/AbstractConstructor";
import LatLonHeight from "../Core/LatLonHeight";
import Model from "../Models/Definition/Model";
import { GlyphStyle } from "../ReactViews/Custom/Chart/Glyphs";
Expand Down Expand Up @@ -65,7 +65,9 @@ export interface ChartItem {
glyphStyle?: GlyphStyle;
}

function ChartableMixin<T extends Constructor<Model<MappableTraits>>>(Base: T) {
function ChartableMixin<T extends AbstractConstructor<Model<MappableTraits>>>(
Base: T
) {
abstract class ChartableMixin extends MappableMixin(Base) {
get isChartable() {
return true;
Expand Down
6 changes: 2 additions & 4 deletions lib/ModelMixins/ClippingMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Transforms from "terriajs-cesium/Source/Core/Transforms";
import CustomDataSource from "terriajs-cesium/Source/DataSources/CustomDataSource";
import ClippingPlane from "terriajs-cesium/Source/Scene/ClippingPlane";
import ClippingPlaneCollection from "terriajs-cesium/Source/Scene/ClippingPlaneCollection";
import Constructor from "../Core/Constructor";
import AbstractConstructor from "../Core/AbstractConstructor";
import filterOutUndefined from "../Core/filterOutUndefined";
import BoxDrawing from "../Models/BoxDrawing";
import CommonStrata from "../Models/Definition/CommonStrata";
Expand All @@ -31,9 +31,7 @@ type InstanceType = BaseType & {
clippingMapItems: CustomDataSource[];
};

function ClippingMixin<T extends Constructor<BaseType>>(
Base: T
): T & Constructor<InstanceType> {
function ClippingMixin<T extends AbstractConstructor<BaseType>>(Base: T) {
abstract class MixedClass extends Base implements InstanceType {
private _clippingBoxDrawing?: BoxDrawing;
abstract clippingPlanesOriginMatrix(): Matrix4;
Expand Down
6 changes: 3 additions & 3 deletions lib/ModelMixins/DiscretelyTimeVaryingMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import binarySearch from "terriajs-cesium/Source/Core/binarySearch";
import JulianDate from "terriajs-cesium/Source/Core/JulianDate";
import { ChartPoint } from "../Charts/ChartData";
import getChartColorForId from "../Charts/getChartColorForId";
import Constructor from "../Core/Constructor";
import AbstractConstructor from "../Core/AbstractConstructor";
import filterOutUndefined from "../Core/filterOutUndefined";
import isDefined from "../Core/isDefined";
import TerriaError from "../Core/TerriaError";
Expand All @@ -27,7 +27,7 @@ export interface DiscreteTimeAsJS {
}

function DiscretelyTimeVaryingMixin<
T extends Constructor<Model<DiscretelyTimeVaryingTraits>>
T extends AbstractConstructor<Model<DiscretelyTimeVaryingTraits>>
>(Base: T) {
abstract class DiscretelyTimeVaryingMixin
extends ChartableMixin(Base)
Expand Down Expand Up @@ -407,7 +407,7 @@ function toJulianDate(time: string | undefined): JulianDate | undefined {
const julianDate = JulianDate.fromIso8601(time);

// Don't return an invalid JulianDate
if (julianDate.secondsOfDay === NaN || julianDate.dayNumber === NaN)
if (isNaN(julianDate.secondsOfDay) || isNaN(julianDate.dayNumber))
return undefined;

return julianDate;
Expand Down
8 changes: 4 additions & 4 deletions lib/ModelMixins/ExportableMixin.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Model from "../Models/Definition/Model";
import Constructor from "../Core/Constructor";
import AbstractConstructor from "../Core/AbstractConstructor";
import ExportableTraits from "../Traits/TraitsClasses/ExportableTraits";
import { computed } from "mobx";

export type ExportData = string | { name: string; file: Blob };

function ExportableMixin<T extends Constructor<Model<ExportableTraits>>>(
Base: T
) {
function ExportableMixin<
T extends AbstractConstructor<Model<ExportableTraits>>
>(Base: T) {
abstract class ExportableMixin extends Base {
protected abstract get _canExportData(): boolean;

Expand Down
15 changes: 8 additions & 7 deletions lib/ModelMixins/GeojsonMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ interface FeatureCounts {

function GeoJsonMixin<T extends Constructor<Model<GeoJsonTraits>>>(Base: T) {
abstract class GeoJsonMixin extends TableMixin(
FeatureInfoUrlTemplateMixin(UrlMixin(CatalogMemberMixin(Base)))
FeatureInfoUrlTemplateMixin(UrlMixin(Base))
) {
@observable
private _dataSource:
Expand Down Expand Up @@ -327,16 +327,17 @@ function GeoJsonMixin<T extends Constructor<Model<GeoJsonTraits>>>(Base: T) {
return true;
}

@computed get name() {
protected nameOverride(traitValue: string | undefined) {
const superValue = super.nameOverride(traitValue);
if (CatalogMemberMixin.isMixedInto(this.sourceReference)) {
return super.name || this.sourceReference.name;
return superValue || this.sourceReference.name;
}
return super.name;
return superValue;
}

@computed get cacheDuration(): string {
if (isDefined(super.cacheDuration)) {
return super.cacheDuration;
protected cacheDurationOverride(traitValue: string | undefined) {
if (isDefined(traitValue)) {
return traitValue;
}
return "1d";
}
Expand Down
8 changes: 3 additions & 5 deletions lib/ModelMixins/GltfMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ function GltfMixin<T extends Constructor<GltfModel>>(Base: T) {
return true;
}

@computed
get disableZoomTo() {
protected disableZoomToOverride(traitValue: boolean) {
const { latitude, longitude, height } = this.origin;
return (
latitude === undefined ||
Expand Down Expand Up @@ -164,12 +163,11 @@ function GltfMixin<T extends Constructor<GltfModel>>(Base: T) {
return Promise.resolve();
}

@computed
get shortReport(): string | undefined {
protected shortReportOverride(traitValue: string | undefined) {
if (this.terria.currentViewer.type === "Leaflet") {
return i18next.t("models.commonModelErrors.3dTypeIn2dMode", this);
}
return super.shortReport;
return traitValue;
}

@computed
Expand Down
2 changes: 1 addition & 1 deletion lib/ModelMixins/GroupMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function GroupMixin<T extends Constructor<Model<GroupTraits>>>(Base: T) {
*
* {@see AsyncLoader}
*/
protected abstract async forceLoadMembers(): Promise<void>;
protected abstract forceLoadMembers(): Promise<void>;

@action
toggleOpen(stratumId: string) {
Expand Down
18 changes: 15 additions & 3 deletions lib/ModelMixins/MappableMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import DataSource from "terriajs-cesium/Source/DataSources/DataSource";
import Cesium3DTileset from "terriajs-cesium/Source/Scene/Cesium3DTileset";
import ImageryProvider from "terriajs-cesium/Source/Scene/ImageryProvider";
import AsyncLoader from "../Core/AsyncLoader";
import Constructor from "../Core/Constructor";
import AbstractConstructor from "../Core/AbstractConstructor";
import Result from "../Core/Result";
import Model from "../Models/Definition/Model";
import MappableTraits from "../Traits/TraitsClasses/MappableTraits";
Expand Down Expand Up @@ -40,6 +40,10 @@ export namespace ImageryParts {
}
}

export function isImagery(mapItem: MapItem): mapItem is AbstractPrimitive {
Copy link
Member

Choose a reason for hiding this comment

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

Should the is X type here be ImageryParts?

Suggested change
export function isImagery(mapItem: MapItem): mapItem is AbstractPrimitive {
export function isImagery(mapItem: MapItem): mapItem is ImageryParts {

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied this from the ts4-interfaces branch, so I'm not actually sure. It sounds right to me, though.

return ImageryParts.is(mapItem);
}

export function isPrimitive(mapItem: MapItem): mapItem is AbstractPrimitive {
return "isDestroyed" in mapItem;
}
Expand All @@ -60,7 +64,15 @@ export function isDataSource(object: MapItem): object is DataSource {
return "entities" in object;
}

function MappableMixin<T extends Constructor<Model<MappableTraits>>>(Base: T) {
export function setShow(mapItem: MapItem, show: boolean) {
if ("show" in mapItem) {
mapItem.show = show;
}
}

function MappableMixin<T extends AbstractConstructor<Model<MappableTraits>>>(
Base: T
) {
abstract class MappableMixin extends Base {
initialMessageShown: boolean = false;
get isMappable() {
Expand Down Expand Up @@ -162,7 +174,7 @@ function MappableMixin<T extends Constructor<Model<MappableTraits>>>(Base: T) {
*
* {@see AsyncLoader}
*/
protected abstract async forceLoadMapItems(): Promise<void>;
protected abstract forceLoadMapItems(): Promise<void>;

/**
* Array of MapItems to show on the map/chart when Catalog Member is shown
Expand Down
4 changes: 2 additions & 2 deletions lib/ModelMixins/ShadowMixin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import i18next from "i18next";
import { computed, runInAction } from "mobx";
import ShadowMode from "terriajs-cesium/Source/Scene/ShadowMode";
import Constructor from "../Core/Constructor";
import AbstractConstructor from "../Core/AbstractConstructor";
import Model from "../Models/Definition/Model";
import SelectableDimensions, {
SelectableDimension
Expand All @@ -10,7 +10,7 @@ import ShadowTraits from "../Traits/TraitsClasses/ShadowTraits";

type BaseType = Model<ShadowTraits> & SelectableDimensions;

function ShadowMixin<T extends Constructor<BaseType>>(Base: T) {
function ShadowMixin<T extends AbstractConstructor<BaseType>>(Base: T) {
abstract class ShadowMixin extends Base {
get hasShadows() {
return true;
Expand Down
11 changes: 6 additions & 5 deletions lib/ModelMixins/TableMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import DataSource from "terriajs-cesium/Source/DataSources/DataSource";
import ImageryProvider from "terriajs-cesium/Source/Scene/ImageryProvider";
import { ChartPoint } from "../Charts/ChartData";
import getChartColorForId from "../Charts/getChartColorForId";
import Constructor from "../Core/Constructor";
import AbstractConstructor from "../Core/AbstractConstructor";
import filterOutUndefined from "../Core/filterOutUndefined";
import flatten from "../Core/flatten";
import isDefined from "../Core/isDefined";
Expand Down Expand Up @@ -56,7 +56,9 @@ import DiscretelyTimeVaryingMixin, {
import ExportableMixin, { ExportData } from "./ExportableMixin";
import { ImageryParts } from "./MappableMixin";

function TableMixin<T extends Constructor<Model<TableTraits>>>(Base: T) {
function TableMixin<T extends AbstractConstructor<Model<TableTraits>>>(
Base: T
) {
abstract class TableMixin
extends ExportableMixin(
DiscretelyTimeVaryingMixin(CatalogMemberMixin(Base))
Expand Down Expand Up @@ -235,8 +237,7 @@ function TableMixin<T extends Constructor<Model<TableTraits>>>(Base: T) {
});
}

@computed
get disableZoomTo() {
protected disableZoomOverride(traitValue: boolean) {
// Disable zoom if only showing imagery parts (eg region mapping) and no rectangle is defined
if (
!this.mapItems.find(
Expand All @@ -246,7 +247,7 @@ function TableMixin<T extends Constructor<Model<TableTraits>>>(Base: T) {
) {
return true;
}
return super.disableZoomTo;
return traitValue;
}

/** Is showing regions (instead of points) */
Expand Down
Loading