Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
Bump typescript to 5.0.3 (#5636)
Browse files Browse the repository at this point in the history
**User-Facing Changes**
None

**Description**

- Bumps typescript to 5.0
- Removes some type hacks now that the builtin lib has better
OffscreenCanvas types (see
microsoft/TypeScript-DOM-lib-generator#1480)
  • Loading branch information
jtbandes committed Apr 6, 2023
1 parent fd12e27 commit b6db0da
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 149 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -88,7 +88,7 @@
"@types/jest": "29.4.0",
"@types/license-checker": "^25.0.3",
"@types/semver": "^7.3.13",
"@typescript-eslint/eslint-plugin": "5.56.0",
"@typescript-eslint/eslint-plugin": "5.57.0",
"@typescript-eslint/parser": "5.57.0",
"babel-plugin-transform-import-meta": "2.2.0",
"cross-env": "7.0.3",
Expand Down Expand Up @@ -117,7 +117,7 @@
"ts-node": "10.9.1",
"ts-prune": "0.10.3",
"tslib": "2.5.0",
"typescript": "4.9.5",
"typescript": "5.0.3",
"typescript-plugin-css-modules": "4.2.3",
"webpack": "5.76.2",
"webpack-cli": "5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/comlink-transfer-handlers/package.json
Expand Up @@ -21,6 +21,6 @@
},
"devDependencies": {
"comlink": "4.4.1",
"typescript": "4.9.5"
"typescript": "5.0.3"
}
}
2 changes: 1 addition & 1 deletion packages/hooks/package.json
Expand Up @@ -21,7 +21,7 @@
},
"devDependencies": {
"@testing-library/react-hooks": "8.0.1",
"typescript": "4.9.5"
"typescript": "5.0.3"
},
"dependencies": {
"@foxglove/log": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/log/package.json
Expand Up @@ -20,6 +20,6 @@
"prepack": "tsc -b"
},
"devDependencies": {
"typescript": "4.9.5"
"typescript": "5.0.3"
}
}
2 changes: 1 addition & 1 deletion packages/mcap-support/package.json
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"@types/protobufjs": "workspace:*",
"typescript": "4.9.5"
"typescript": "5.0.3"
},
"dependencies": {
"@foxglove/message-definition": "0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/studio-base/package.json
Expand Up @@ -174,7 +174,7 @@
"ts-key-enum": "2.0.12",
"ts-loader": "9.4.2",
"tss-react": "4.8.2",
"typescript": "4.9.5",
"typescript": "5.0.3",
"url-search-params": "1.1.0",
"use-debounce": "9.0.3",
"use-immer": "0.8.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/studio-base/src/components/Chart/index.tsx
Expand Up @@ -88,7 +88,7 @@ function rpcMouseEvent(event: React.MouseEvent<HTMLElement>) {
type RpcSend = <T>(
topic: string,
payload?: Record<string, unknown>,
transferables?: (Transferable | OffscreenCanvas)[],
transferables?: Transferable[],
) => Promise<T>;

// Chart component renders data using workers with chartjs offscreen canvas
Expand Down Expand Up @@ -137,7 +137,7 @@ function Chart(props: Props): JSX.Element {
const sendWrapper = async <T,>(
topic: string,
payload?: Record<string, unknown>,
transferables?: (Transferable | OffscreenCanvas)[],
transferables?: Transferable[],
) => {
return await rpc.send<T>(topic, { id, ...payload }, transferables);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/studio-base/src/components/CreateEventDialog.tsx
Expand Up @@ -252,7 +252,7 @@ export function CreateEventDialog(props: { onClose: () => void }): JSX.Element {
<FormLabel>Metadata</FormLabel>
<div className={classes.grid}>
{event.metadataEntries.map(({ key, value }, index) => {
const hasDuplicate = ((key.length > 0 && countedMetadata[key]) ?? 0) > 1;
const hasDuplicate = ((key.length > 0 ? countedMetadata[key] : undefined) ?? 0) > 1;
return (
<div className={classes.row} key={index}>
<TextField
Expand Down
Expand Up @@ -47,13 +47,8 @@ class ImageCanvasWorker {

const matrix = (state.dimensions?.transform ?? new DOMMatrix()).inverse();
const point = new DOMPoint(x, y).matrixTransform(matrix);
// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1480
const pixel = (
state.canvas.getContext("2d") as OffscreenCanvasRenderingContext2D | undefined
)?.getImageData(x, y, 1, 1);
const hit = (
state.hitmap.getContext("2d") as OffscreenCanvasRenderingContext2D | undefined
)?.getImageData(x, y, 1, 1);
const pixel = state.canvas.getContext("2d")?.getImageData(x, y, 1, 1);
const hit = state.hitmap.getContext("2d")?.getImageData(x, y, 1, 1);
const markerIndex = hit ? idColorToIndex(hit.data) : undefined;

if (pixel) {
Expand Down
Expand Up @@ -16,10 +16,7 @@ export class HitmapRenderContext {
private readonly _ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D,
private readonly _hitmapCanvas: HTMLCanvasElement | OffscreenCanvas | undefined,
) {
this._hctx = (this._hitmapCanvas?.getContext("2d") ?? undefined) as
| CanvasRenderingContext2D
| OffscreenCanvasRenderingContext2D
| undefined;
this._hctx = this._hitmapCanvas?.getContext("2d") ?? undefined;
if (this._hctx) {
this._hctx.imageSmoothingEnabled = false;
this._hctx.clearRect(0, 0, this._ctx.canvas.width, this._ctx.canvas.height);
Expand Down
13 changes: 2 additions & 11 deletions packages/studio-base/src/panels/Image/lib/renderImage.ts
Expand Up @@ -193,13 +193,7 @@ function decodeMessageToBitmap(

function clearCanvas(canvas?: RenderableCanvas) {
if (canvas) {
// https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1480
(
canvas.getContext("2d") as
| CanvasRenderingContext2D
| OffscreenCanvasRenderingContext2D
| undefined
)?.clearRect(0, 0, canvas.width, canvas.height);
canvas.getContext("2d")?.clearRect(0, 0, canvas.width, canvas.height);
}
}

Expand All @@ -223,10 +217,7 @@ function render({
? { width: bitmap.width, height: bitmap.height }
: { width: bitmap.height, height: bitmap.width };

const canvasCtx = canvas.getContext("2d") as // https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1480
| CanvasRenderingContext2D
| OffscreenCanvasRenderingContext2D
| undefined;
const canvasCtx = canvas.getContext("2d");
if (!canvasCtx) {
return;
}
Expand Down
Expand Up @@ -37,7 +37,6 @@ const createProperty = (name: string | ts.PropertyName, type: ts.TypeNode) => {

const createTimeInterfaceDeclaration = (name: string) => {
return ts.factory.createInterfaceDeclaration(
undefined /* decorators */,
modifiers /* modifiers */,
name /* name */,
undefined /* typeParameters */,
Expand All @@ -51,8 +50,6 @@ const createTimeInterfaceDeclaration = (name: string) => {

// Since rosbagjs treats json as a primitive, we have to shim it in.
const jsonInterfaceDeclaration = ts.factory.createInterfaceDeclaration(
undefined,
/* decorators */
modifiers,
/* modifiers */
"json",
Expand Down Expand Up @@ -134,7 +131,6 @@ export const generateTypeDefs = (datatypes: RosDatatypes): InterfaceDeclarations
});

interfaceDeclarations[datatype] = ts.factory.createInterfaceDeclaration(
undefined /* decorators */,
[ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)] /* modifiers */,
formatInterfaceName(datatype) /* name */,
undefined /* typeParameters */,
Expand All @@ -155,7 +151,6 @@ const generateRosLib = ({
datatypes: RosDatatypes;
}): string => {
let TopicsToMessageDefinition = ts.factory.createInterfaceDeclaration(
undefined,
modifiers,
"TopicsToMessageDefinition",
undefined,
Expand All @@ -164,8 +159,6 @@ const generateRosLib = ({
);

const typedMessage = ts.factory.createInterfaceDeclaration(
undefined,
/* decorators */
modifiers,
/* modifiers */
"Input",
Expand Down
12 changes: 10 additions & 2 deletions packages/studio-base/src/theme/muiComponents.ts
Expand Up @@ -2,7 +2,15 @@
// License, v2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/

import { alpha, Fade, Theme, dividerClasses, listClasses, listItemClasses } from "@mui/material";
import {
alpha,
CSSInterpolation,
Fade,
Theme,
dividerClasses,
listClasses,
listItemClasses,
} from "@mui/material";
import { CSSProperties } from "react";
import tinycolor from "tinycolor2";

Expand All @@ -15,7 +23,7 @@ type MuiLabComponents = {
MuiToggleButton?: {
styleOverrides?: {
root?: CSSProperties;
label?: CSSProperties;
label?: CSSInterpolation;
};
};
MuiToggleButtonGroup?: {
Expand Down
4 changes: 2 additions & 2 deletions packages/studio-base/src/util/Rpc.ts
Expand Up @@ -15,7 +15,7 @@
// instances of web-workers and shared-workers respectively, as well as avaiable on
// 'global' within them.
export interface Channel {
postMessage(data: unknown, transfer?: (Transferable | OffscreenCanvas)[]): void;
postMessage(data: unknown, transfer?: Transferable[]): void;
onmessage?: ((ev: MessageEvent) => unknown) | null; // eslint-disable-line no-restricted-syntax
terminate: () => void;
}
Expand Down Expand Up @@ -154,7 +154,7 @@ export default class Rpc {
public async send<TResult, TData = unknown>(
topic: string,
data?: TData,
transfer?: (Transferable | OffscreenCanvas)[],
transfer?: Transferable[],
): Promise<TResult> {
const id = this._messageId++;
const message = { topic, id, data };
Expand Down
6 changes: 5 additions & 1 deletion packages/studio-base/webpack.ts
Expand Up @@ -181,7 +181,7 @@ export function makeConfig(
options: {
multiple: [
{
search: "etwModule = require(etwModulePath);",
search: /etwModule\s*=\s*require\(etwModulePath\);/,
replace:
"throw new Error('[Foxglove] This module is not supported in the browser.');",
},
Expand All @@ -200,6 +200,10 @@ export function makeConfig(
replace:
"throw new Error('[Foxglove] This module is not supported in the browser.');",
},
{
search: `return { module: require(modulePath), modulePath, error: void 0 };`,
replace: `throw new Error('[Foxglove] This module is not supported in the browser.');`,
},
{
search: `getModuleResolver=function(e){let t;try{t=require(e)}`,
replace:
Expand Down
2 changes: 1 addition & 1 deletion packages/studio/package.json
Expand Up @@ -19,6 +19,6 @@
"prepack": "tsc -b tsconfig.json"
},
"devDependencies": {
"typescript": "4.9.5"
"typescript": "5.0.3"
}
}
2 changes: 1 addition & 1 deletion packages/typescript-transformers/package.json
Expand Up @@ -20,6 +20,6 @@
"prepack": "tsc -b"
},
"dependencies": {
"typescript": "4.9.5"
"typescript": "5.0.3"
}
}
Expand Up @@ -48,6 +48,6 @@ export function createTssReactNameTransformer(
}
return ts.visitEachChild(node, visitor, context);
};
return ts.visitNode(sourceFile, visitor);
return ts.visitNode(sourceFile, visitor, ts.isSourceFile);
};
}

0 comments on commit b6db0da

Please sign in to comment.