Skip to content

Commit

Permalink
Upgrade to TS 5.6.
Browse files Browse the repository at this point in the history
Mainly implements a workaround for error TS2855 that prevents accessing parent class
fields as `super.field` [introduced in TS
5.3](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#checks-for-super-property-accesses-on-instance-fields). In
valid JS, super can only be used to access get/set accessors or methods from
parent classes that are declared on the prototype, but not instance
fields (declared as `x = "something"`). In our case though, traits are declared
as getters and not fields, however because we use mapped types to mixin the
traits into a class and mapped types does not allow specifying getter/setter
variants, TS considers our traits to be fields and raises TS2855.

The workaround in this PR defines these erroring traits as getters which seems
to convince TS (at least for now) that they are valid accessors eventhough they
still are typed using mapped.

Hopefully in the future, we get this TS feature implementing [variant accessors
for mapped types](microsoft/TypeScript#43826), then
we can get rid of this workaround.
  • Loading branch information
na9da committed Nov 24, 2024
1 parent 91466b0 commit c64b16a
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 34 deletions.
4 changes: 2 additions & 2 deletions lib/Map/Region/RegionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,8 @@ export default class RegionProvider {
if (!isDefined(disambigCode)) {
// we have an ambiguous value, but nothing with which to disambiguate. We pick the first, warn.
console.warn(
"Ambiguous value found in region mapping: " + codeAfterReplacement ??
code
"Ambiguous value found in region mapping: " +
(codeAfterReplacement || code)
);
return ids[0];
}
Expand Down
8 changes: 4 additions & 4 deletions lib/ModelMixins/GeojsonMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ import {
} from "mobx";
import { createTransformer } from "mobx-utils";
import {
Feature as ProtomapsFeature,
GeomType,
LineSymbolizer,
PolygonSymbolizer
PolygonSymbolizer,
Feature as ProtomapsFeature
} from "protomaps";
import Cartesian2 from "terriajs-cesium/Source/Core/Cartesian2";
import Cartesian3 from "terriajs-cesium/Source/Core/Cartesian3";
Expand Down Expand Up @@ -77,8 +77,8 @@ import { isJson } from "../Core/loadBlob";
import StandardCssColors from "../Core/StandardCssColors";
import TerriaError, { networkRequestError } from "../Core/TerriaError";
import ProtomapsImageryProvider, {
GeojsonSource,
GEOJSON_SOURCE_LAYER_NAME,
GeojsonSource,
ProtomapsData
} from "../Map/ImageryProvider/ProtomapsImageryProvider";
import Reproject from "../Map/Vector/Reproject";
Expand Down Expand Up @@ -1491,7 +1491,7 @@ export function toFeatureCollection(
}
if (Array.isArray(json) && json.every((item) => isGeometries(item))) {
return featureCollection(
json.map((item) => feature(item, item.properties))
json.map((item) => feature(item))
) as FeatureCollectionWithCrs;
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Models/Catalog/CatalogItems/OpenDataSoftCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,8 +631,8 @@ export default class OpenDataSoftCatalogItem
([field, value]) => {
// geoPoint2dFieldName will return a JSON object - spilt lat/lon columns
if (field === this.geoPoint2dFieldName && isJsonObject(value)) {
cols.lat[index] = `${value.lat}` ?? "";
cols.lon[index] = `${value.lon}` ?? "";
cols.lat[index] = `${value.lat}`;
cols.lon[index] = `${value.lon}`;
} else {
// Copy current field into columns object
if (!Array.isArray(cols[field])) {
Expand Down
30 changes: 20 additions & 10 deletions lib/Traits/TraitsClasses/CatalogMemberTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,19 @@ class CatalogMemberTraits extends ModelTraits {
name: "Name",
description: "The name of the catalog item."
})
name?: string;
get name(): string | undefined {
return;
}

@primitiveTrait({
type: "string",
name: "Description",
description:
"The description of the catalog item. Markdown and HTML may be used."
})
description?: string;
get description(): string | undefined {
return;
}

@primitiveTrait({
type: "boolean",
Expand All @@ -131,7 +135,9 @@ class CatalogMemberTraits extends ModelTraits {
description:
"The name of the item to be displayed in the catalog, if it is different from the one to display in the workbench."
})
nameInCatalog?: string;
get nameInCatalog(): string | undefined {
return;
}

@objectArrayTrait({
type: InfoSectionTraits,
Expand Down Expand Up @@ -174,7 +180,9 @@ class CatalogMemberTraits extends ModelTraits {
name: "Short report",
description: "A short report to show on the now viewing tab."
})
shortReport?: string;
get shortReport(): string | undefined {
return;
}

@objectArrayTrait({
type: ShortReportTraits,
Expand Down Expand Up @@ -238,7 +246,9 @@ class CatalogMemberTraits extends ModelTraits {
name: "Disable about data",
description: "Disables the 'About Data' button in the workbench."
})
disableAboutData?: boolean;
get disableAboutData(): boolean | undefined {
return;
}

@primitiveTrait({
type: "boolean",
Expand All @@ -249,14 +259,14 @@ class CatalogMemberTraits extends ModelTraits {
shareable: boolean = true;
}

/* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
// /* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
interface CatalogMemberTraits {
// Add traits here that you want to override from some Mixin or Model class
// without generating TS2611 type error.
name?: CatalogMemberTraits["name"];
shortReport?: CatalogMemberTraits["shortReport"];
description?: CatalogMemberTraits["description"];
disableAboutData?: CatalogMemberTraits["disableAboutData"];
name: CatalogMemberTraits["name"];
shortReport: CatalogMemberTraits["shortReport"];
description: CatalogMemberTraits["description"];
disableAboutData: CatalogMemberTraits["disableAboutData"];
}

export default CatalogMemberTraits;
4 changes: 3 additions & 1 deletion lib/Traits/TraitsClasses/GetCapabilitiesTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export default class GetCapabilitiesTraits extends ModelTraits {
description:
"The URL at which to access to the OGC GetCapabilities service."
})
getCapabilitiesUrl?: string;
get getCapabilitiesUrl(): string | undefined {
return;
}

@primitiveTrait({
type: "string",
Expand Down
4 changes: 3 additions & 1 deletion lib/Traits/TraitsClasses/HighlightColorTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ export default class HighlightColorTraits extends ModelTraits {
description:
"The color used to highlight a feature when it is picked. If not set, this defaults to `Terria.baseMapContrastColor`"
})
highlightColor?: string;
get highlightColor(): string | undefined {
return;
}
}
6 changes: 4 additions & 2 deletions lib/Traits/TraitsClasses/MappableTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ class MappableTraits extends mixTraits(AttributionTraits) {
description:
"Disables the zoom to (aka 'Ideal Zoom') button in the workbench."
})
disableZoomTo: boolean = false;
get disableZoomTo(): boolean {
return false;
}

@primitiveTrait({
type: "boolean",
Expand Down Expand Up @@ -281,7 +283,7 @@ class MappableTraits extends mixTraits(AttributionTraits) {
maximumShownFeatureInfos?: number;
}

/* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
// /* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
interface MappableTraits {
// Add traits here that you want to override from some Mixin or Model class
// without generating TS2611 type error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,7 @@ export default class SensorObservationCatalogItemTraits extends mixTraits(
type: "string",
description: "The identifier of the selected observable property"
})
selectedObservableId?: string;
get selectedObservableId(): string | undefined {
return;
}
}
16 changes: 12 additions & 4 deletions lib/Traits/TraitsClasses/TimeVaryingTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export default class TimeVaryingTraits extends mixTraits(CatalogMemberTraits) {
type: "string",
isNullable: true
})
currentTime?: string | null;
get currentTime(): string | null | undefined {
return;
}

@primitiveTrait({
name: "Initial Time Source",
Expand All @@ -37,23 +39,29 @@ export default class TimeVaryingTraits extends mixTraits(CatalogMemberTraits) {
"The earliest time for which this dataset is available. This will be the start of the range shown on the timeline control.",
type: "string"
})
startTime?: string;
get startTime(): string | undefined {
return;
}

@primitiveTrait({
name: "Stop Time",
description:
"The latest time for which this dataset is available. This will be the end of the range shown on the timeline control.",
type: "string"
})
stopTime?: string;
get stopTime(): string | undefined {
return;
}

@primitiveTrait({
name: "Time Multiplier",
description:
"The multiplier to use in progressing time for this dataset. For example, `5.0` means that five seconds of dataset time will pass for each one second of real time.",
type: "number"
})
multiplier?: number;
get multiplier(): number | undefined {
return;
}

@primitiveTrait({
name: "Is Paused",
Expand Down
18 changes: 12 additions & 6 deletions lib/Traits/TraitsClasses/UrlTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,37 @@ class UrlTraits extends ModelTraits {
name: "URL",
description: "The base URL of the file or service."
})
url?: string;
get url(): string | undefined {
return;
}

@primitiveTrait({
type: "boolean",
name: "Force proxy",
description: "Force the default proxy to be used for all network requests."
})
forceProxy?: boolean;
get forceProxy(): boolean | undefined {
return;
}

@primitiveTrait({
type: "string",
name: "Cache Duration",
description:
"The cache duration to use for proxied URLs for this catalog member. If undefined, proxied URLs are effectively cachable forever. The duration is expressed as a Varnish-like duration string, such as '1d' (one day) or '10000s' (ten thousand seconds)."
})
cacheDuration?: string;
get cacheDuration(): string | undefined {
return;
}
}

/* eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging */
interface UrlTraits {
// Add traits here that you want to override from some Mixin or Model class
// without generating TS2611 type error.
url?: UrlTraits["url"];
cacheDuration?: UrlTraits["cacheDuration"];
forceProxy?: UrlTraits["forceProxy"];
url: UrlTraits["url"];
cacheDuration: UrlTraits["cacheDuration"];
forceProxy: UrlTraits["forceProxy"];
}

export default UrlTraits;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
"thredds-catalog-crawler": "0.0.7",
"ts-essentials": "^5.0.0",
"ts-loader": "^5.3.3",
"typescript": "~5.2.0",
"typescript": "^5.6.2",
"urijs": "^1.18.12",
"url-loader": "^1.1.2",
"webpack": "~4.47.0",
Expand Down

0 comments on commit c64b16a

Please sign in to comment.