Skip to content

Commit 215fad8

Browse files
authored
fix: Remove un-typesafe cast. (#9052)
1 parent 083329a commit 215fad8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

core/utils/dom.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,13 @@ export function getFastTextWidthWithSizeString(
289289
// Initialize the HTML canvas context and set the font.
290290
// The context font must match blocklyText's fontsize and font-family
291291
// set in CSS.
292-
canvasContext = computeCanvas.getContext('2d') as CanvasRenderingContext2D;
292+
canvasContext = computeCanvas.getContext('2d');
293293
}
294-
// Set the desired font size and family.
295-
canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily;
296294

297295
// Measure the text width using the helper canvas context.
298-
if (text) {
296+
if (text && canvasContext) {
297+
// Set the desired font size and family.
298+
canvasContext.font = fontWeight + ' ' + fontSize + ' ' + fontFamily;
299299
width = canvasContext.measureText(text).width;
300300
} else {
301301
width = 0;

0 commit comments

Comments
 (0)