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

Update to Typescript v5.5.0 #7878

Merged
merged 7 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions frontend/javascripts/admin/datastore_health_check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const pingDataStoreIfAppropriate = memoizedThrottle(async (requestedUrl: string)
return;
}

// @ts-expect-error ts-migrate(2769) FIXME: No overload matches this call.
const stores = datastores
.map((datastore) => ({ ...datastore, path: "data" }))
.concat({ ...tracingstore, path: "tracings" });
const stores = [
{ ...tracingstore, path: "tracings" },
...datastores.map((datastore) => ({ ...datastore, path: "data" })),
];

if (isInMaintenance) {
Toast.warning(messages.planned_maintenance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ function ensureValidScaleOnInferredDataSource(
if (
segmentationLayerSettings != null &&
savedSegmentationLayerSettings != null &&
// @ts-expect-error ts-migrate(2339) FIXME: Property 'largestSegmentId' does not exist on type... Remove this comment to see the full error message
segmentationLayerSettings.largestSegmentId === 0 && // Flow needs this additional check to understand that segmentationLayerSettings is for the segmentation layer.
savedSegmentationLayerSettings.category === "segmentation" &&
segmentationLayerSettings.category === "segmentation"
Expand Down
1 change: 0 additions & 1 deletion frontend/javascripts/oxalis/api/api_latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2177,7 +2177,6 @@ class DataApi {

if (
state.localSegmentationData[effectiveLayerName].availableMeshFiles == null ||
// @ts-expect-error ts-migrate(2533) FIXME: Object is possibly 'null' or 'undefined'.
!state.localSegmentationData[effectiveLayerName].availableMeshFiles.find(
(el) => el.meshFileName === meshFileName,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ const getResolutionInfoOfActiveSegmentationTracingLayer = memoizeOne(
export function getServerVolumeTracings(
tracings: Array<ServerTracing> | null | undefined,
): Array<ServerVolumeTracing> {
// @ts-expect-error ts-migrate(2322) FIXME: Type 'ServerTracing[]' is not assignable to type '... Remove this comment to see the full error message
const volumeTracings: Array<ServerVolumeTracing> = (tracings || []).filter(
(tracing) => tracing.typ === "Volume",
);
const volumeTracings = (tracings || []).filter((tracing) => tracing.typ === "Volume");
return volumeTracings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
MISSING_GROUP_ID,
} from "oxalis/view/right-border-tabs/tree_hierarchy_view_helpers";
type GroupNode = {
children: Array<GroupNode>;
children: GroupNode[];
groupId: number | null | undefined;
parent: GroupNode | null | undefined;
};
Expand All @@ -29,7 +29,7 @@ function buildTreeGroupHashMap(skeletonTracing: SkeletonTracing): Record<number,
parent: null,
};

function createSubTree(subTreeRoot: GroupNode, children: Array<TreeGroup>) {
function createSubTree(subTreeRoot: GroupNode, children: TreeGroup[]) {
for (const child of children) {
const childNode = {
children: [],
Expand Down Expand Up @@ -62,9 +62,9 @@ function buildTreeGroupHashMap(skeletonTracing: SkeletonTracing): Record<number,
function findCommonAncestor(
treeIdMap: TreeMap,
groupIdMap: Record<number, GroupNode>,
toggleActions: Array<UpdateTreeVisibilityUpdateAction>,
toggleActions: UpdateTreeVisibilityUpdateAction[],
): number | undefined {
function getAncestorPath(groupId: number | null | undefined): Array<number> {
function getAncestorPath(groupId: number | null | undefined): number[] {
const path = [];
let currentGroupNode: GroupNode | null | undefined =
groupIdMap[groupId == null ? MISSING_GROUP_ID : groupId];
Expand Down Expand Up @@ -114,13 +114,10 @@ function isCommonAncestorToggler(
): [boolean, Tree[], number] {
const groupToTreesMap = createGroupToTreesMap(skeletonTracing.trees);
const groupWithSubgroups = getGroupByIdWithSubgroups(skeletonTracing.treeGroups, commonAncestor);
const allTreesOfAncestor: Array<Tree> =
const allTreesOfAncestor: Tree[] =
groupWithSubgroups.length === 0
? _.values(skeletonTracing.trees)
: _.flatMap(
groupWithSubgroups,
(groupId: number): Array<Tree> => groupToTreesMap[groupId] || [],
);
: _.flatMap(groupWithSubgroups, (groupId: number): Tree[] => groupToTreesMap[groupId] || []);

const [visibleTrees, invisibleTrees] = _.partition(allTreesOfAncestor, (tree) => tree.isVisible);

Expand All @@ -140,9 +137,9 @@ function isCommonAncestorToggler(
}

export default function compactToggleActions(
updateActions: Array<UpdateAction>,
updateActions: UpdateAction[],
tracing: SkeletonTracing | VolumeTracing,
): Array<UpdateAction> {
): UpdateAction[] {
if (tracing.type !== "skeleton") {
// Don't do anything if this is not a skeleton tracing
return updateActions;
Expand All @@ -156,7 +153,7 @@ export default function compactToggleActions(
(ua) => ua.name === "updateTreeVisibility",
);

const toggleActions = _toggleActions as any as Array<UpdateTreeVisibilityUpdateAction>;
const toggleActions = _toggleActions as any as UpdateTreeVisibilityUpdateAction[];

if (toggleActions.length <= 1) {
// Don't try to compact actons if there are no or only one toggleAction(s)
Expand All @@ -181,5 +178,5 @@ export default function compactToggleActions(
...exceptions.map((tree) => updateTreeVisibility(tree)),
];
const finalToggleActions = shouldUseToggleGroup ? compactedToggleActions : toggleActions;
return remainingActions.concat(finalToggleActions);
return [...remainingActions, ...finalToggleActions];
Copy link
Member

Choose a reason for hiding this comment

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

I'd be careful with array spreads due to performance. Since there might be lots of update actions here, I'd stick to concat.

small microbenchmark in chrome:

console.time("a")
res = arr.concat(arr)
console.timeEnd("a")
console.time("a")
res = [...arr, ...arr]
console.timeEnd("a")

a: 0.332763671875 ms
a: 13.9931640625 ms

Copy link
Member Author

Choose a reason for hiding this comment

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

arghh... 😱

concat drives TS into a rage:

  Overload 1 of 2, '(...items: ConcatArray<UpdateTreeUpdateAction | { readonly name: "deleteTree"; readonly value: { readonly id: number; }; } | { readonly name: "mergeTree"; readonly value: { readonly sourceId: number; readonly targetId: number; }; } | ... 23 more ... | { ...; }>[]): (UpdateTreeUpdateAction | ... 25 more ... | { ...; })[]', gave the following error.
    Argument of type '({ readonly name: "updateTreeVisibility"; readonly value: { readonly treeId: number; readonly isVisible: boolean; }; } | { readonly name: "updateTreeGroupVisibility"; readonly value: { readonly treeGroupId: number | ... 1 more ... | undefined; readonly isVisible: boolean; }; })[]' is not assignable to parameter of type 'ConcatArray<UpdateTreeUpdateAction | { readonly name: "deleteTree"; readonly value: { readonly id: number; }; } | { readonly name: "mergeTree"; readonly value: { readonly sourceId: number; readonly targetId: number; }; } | ... 23 more ... | { ...; }>'.
      The types returned by 'slice(...)' are incompatible between these types.
        Type '({ readonly name: "updateTreeVisibility"; readonly value: { readonly treeId: number; readonly isVisible: boolean; }; } | { readonly name: "updateTreeGroupVisibility"; readonly value: { readonly treeGroupId: number | ... 1 more ... | undefined; readonly isVisible: boolean; }; })[]' is not assignable to type '(UpdateTreeUpdateAction | { readonly name: "deleteTree"; readonly value: { readonly id: number; }; } | { readonly name: "mergeTree"; readonly value: { readonly sourceId: number; readonly targetId: number; }; } | ... 23 more ... | { ...; })[]'.
          Type '{ readonly name: "updateTreeVisibility"; readonly value: { readonly treeId: number; readonly isVisible: boolean; }; } | { readonly name: "updateTreeGroupVisibility"; readonly value: { readonly treeGroupId: number | ... 1 more ... | undefined; readonly isVisible: boolean; }; }' is not assignable to type 'UpdateTreeUpdateAction | { readonly name: "deleteTree"; readonly value: { readonly id: number; }; } | { readonly name: "mergeTree"; readonly value: { readonly sourceId: number; readonly targetId: number; }; } | ... 23 more ... | { ...; }'.
            Type '{ readonly name: "updateTreeVisibility"; readonly value: { readonly treeId: number; readonly isVisible: boolean; }; }' is not assignable to type 'UpdateTreeUpdateAction | { readonly name: "deleteTree"; readonly value: { readonly id: number; }; } | { readonly name: "mergeTree"; readonly value: { readonly sourceId: number; readonly targetId: number; }; } | ... 23 more ... | { ...; }'.
              Type '{ readonly name: "updateTreeVisibility"; readonly value: { readonly treeId: number; readonly isVisible: boolean; }; }' is not assignable to type '{ name: "mergeAgglomerate"; value: { agglomerateId1: number; agglomerateId2: number; mag: Vector3; segmentId1: number | undefined; segmentId2: number | undefined; segmentPosition1?: Vector3 | undefined; segmentPosition2?: Vector3 | undefined; }; }'.
                Types of property 'name' are incompatible.
                  Type '"updateTreeVisibility"' is not assignable to type '"mergeAgglomerate"'.
  Overload 2 of 2, '(...items: (UpdateTreeUpdateAction | { readonly name: "deleteTree"; readonly value: { readonly id: number; }; } | { readonly name: "mergeTree"; readonly value: { readonly sourceId: number; readonly targetId: number; }; } | ... 24 more ... | ConcatArray<...>)[]): (UpdateTreeUpdateAction | ... 25 more ... | { ...; })[]', gave the following error.
    Argument of type '({ readonly name: "updateTreeVisibility"; readonly value: { readonly treeId: number; readonly isVisible: boolean; }; } | { readonly name: "updateTreeGroupVisibility"; readonly value: { readonly treeGroupId: number | ... 1 more ... | undefined; readonly isVisible: boolean; }; })[]' is not assignable to parameter of type 'UpdateTreeUpdateAction | { readonly name: "deleteTree"; readonly value: { readonly id: number; }; } | { readonly name: "mergeTree"; readonly value: { readonly sourceId: number; readonly targetId: number; }; } | ... 24 more ... | ConcatArray<...>'.
      Type '({ readonly name: "updateTreeVisibility"; readonly value: { readonly treeId: number; readonly isVisible: boolean; }; } | { readonly name: "updateTreeGroupVisibility"; readonly value: { readonly treeGroupId: number | ... 1 more ... | undefined; readonly isVisible: boolean; }; })[]' is not assignable to type 'ConcatArray<UpdateTreeUpdateAction | { readonly name: "deleteTree"; readonly value: { readonly id: number; }; } | { readonly name: "mergeTree"; readonly value: { readonly sourceId: number; readonly targetId: number; }; } | ... 23 more ... | { ...; }>'.```

Copy link
Member

Choose a reason for hiding this comment

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

does sth like this work? return (remainingActions as UpdateAction[]).concat(finalToggleActions);

I tested this in a playground with this:

const arr = [1, 2, 3]
const arr2 = [true, false];

(arr as Array<number | boolean>).concat(arr2)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, more or less. see PR feedback commit

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function getSkeletonTracingForConnectome(
layerName: string,
): Maybe<SkeletonTracing> {
if (state.localSegmentationData[layerName].connectomeData.skeleton != null) {
// @ts-expect-error ts-migrate(2322) FIXME: Type 'IMaybe<SkeletonTracing | null | undefined>' ... Remove this comment to see the full error message
return Maybe.Just(state.localSegmentationData[layerName].connectomeData.skeleton);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,7 +1365,7 @@ class SegmentsView extends React.Component<Props, State> {
const relevantSegments =
groupId != null ? this.getSegmentsOfGroupRecursively(groupId) : this.getSelectedSegments();
if (relevantSegments == null) return [];
const segmentsWithoutPosition: number[] = relevantSegments
const segmentsWithoutPosition = relevantSegments
.filter((segment) => segment.somePosition == null)
.map((segment) => segment.id);
return segmentsWithoutPosition.sort();
Expand Down
19 changes: 14 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"sinon": "^12.0.1",
"tmp": "0.0.33",
"ts-loader": "^9.4.1",
"typescript": "^5.3.0",
"typescript": "^5.5.0-beta",
"typescript-coverage-report": "^0.8.0",
"webpack": "^5.74.0",
"webpack-cli": "^5.1.4",
Expand Down Expand Up @@ -220,14 +220,23 @@
"**/rc-tree": "^5.7.12"
},
"ava": {
"files": ["./public-test/test-bundle/**/*.{js,jsx}"],
"ignoredByWatcher": ["./binaryData/**/*.*"],
"require": ["./frontend/javascripts/test/_ava_polyfill_provider.ts"],
"files": [
"./public-test/test-bundle/**/*.{js,jsx}"
],
"ignoredByWatcher": [
"./binaryData/**/*.*"
],
"require": [
"./frontend/javascripts/test/_ava_polyfill_provider.ts"
],
"snapshotDir": "frontend/javascripts/test/snapshots",
"concurrency": 8
},
"c8": {
"exclude": ["public-test/test-bundle/test/**/*.*", "frontend/javascripts/test/**/*.*"],
"exclude": [
"public-test/test-bundle/test/**/*.*",
"frontend/javascripts/test/**/*.*"
],
"reporter": "lcov"
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11485,10 +11485,10 @@ typescript@^5.2.2:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.4.tgz#eb2471e7b0a5f1377523700a21669dce30c2d952"
integrity sha512-dGE2Vv8cpVvw28v8HCPqyb08EzbBURxDpuhJvTrusShUfGnhHBafDsLdS1EhhxyL6BJQE+2cT3dDPAv+MQ6oLw==

typescript@^5.3.0:
version "5.3.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
integrity sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==
typescript@^5.5.0-beta:
version "5.5.0-beta"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.0-beta.tgz#ae6a2e3aa277f74478f1743e8771676cddfcdbec"
integrity sha512-FRg3e/aQg3olEG3ff8YjHOERsO4IM0m4qGrsE4UMvILaq4TdDZ6gQX4+2Rq9SjTpfSe/ebwiHcsjm/7FfWWQ6Q==

uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
Expand Down