diff --git a/core/block_animations.ts b/core/block_animations.ts index 5db01dd3b..68b8d7582 100644 --- a/core/block_animations.ts +++ b/core/block_animations.ts @@ -26,7 +26,7 @@ interface CloneRect { } /** PID of disconnect UI animation. There can only be one at a time. */ -let disconnectPid: AnyDuringMigration = 0; +let disconnectPid: ReturnType|null = null; /** SVG group of wobbling block. There can only be one at a time. */ let disconnectGroup: SVGElement|null = null; @@ -199,7 +199,9 @@ function disconnectUiStep(group: SVGElement, magnitude: number, start: Date) { */ export function disconnectUiStop() { if (disconnectGroup) { - clearTimeout(disconnectPid); + if (disconnectPid) { + clearTimeout(disconnectPid); + } disconnectGroup.setAttribute('transform', ''); disconnectGroup = null; } diff --git a/core/common.ts b/core/common.ts index 342dc935d..18f255d3f 100644 --- a/core/common.ts +++ b/core/common.ts @@ -204,7 +204,7 @@ export const draggingConnections: Connection[] = []; * @alias Blockly.common.getBlockTypeCounts */ export function getBlockTypeCounts( - block: Block, opt_stripFollowing?: boolean): AnyDuringMigration { + block: Block, opt_stripFollowing?: boolean): {[key: string]: number} { const typeCountsMap = Object.create(null); const descendants = block.getDescendants(true); if (opt_stripFollowing) { diff --git a/core/dropdowndiv.ts b/core/dropdowndiv.ts index 6158b73ca..6bc2a9106 100644 --- a/core/dropdowndiv.ts +++ b/core/dropdowndiv.ts @@ -52,7 +52,7 @@ export const ANIMATION_TIME = 0.25; * Timer for animation out, to be cleared if we need to immediately hide * without disrupting new shows. */ -let animateOutTimer: AnyDuringMigration = null; +let animateOutTimer: ReturnType|null = null; /** Callback for when the drop-down is hidden. */ let onHide: Function|null = null; diff --git a/core/extensions.ts b/core/extensions.ts index ae9e3cc39..99ffa809a 100644 --- a/core/extensions.ts +++ b/core/extensions.ts @@ -352,7 +352,7 @@ function mutatorPropertiesMatch( * @throws Error Will throw if no global document can be found (e.g., Node.js). * @internal */ -export function runAfterPageLoad(fn: () => AnyDuringMigration) { +export function runAfterPageLoad(fn: () => void) { if (typeof document !== 'object') { throw Error('runAfterPageLoad() requires browser document.'); } diff --git a/core/flyout_base.ts b/core/flyout_base.ts index c315d9a71..223d930da 100644 --- a/core/flyout_base.ts +++ b/core/flyout_base.ts @@ -158,7 +158,7 @@ export abstract class Flyout extends DeleteArea implements IFlyout { /** * List of event listeners. */ - private listeners_: AnyDuringMigration[][] = []; + private listeners_: browserEvents.Data[] = []; /** * List of blocks that should always be disabled. diff --git a/core/flyout_metrics_manager.ts b/core/flyout_metrics_manager.ts index c52a008f6..38dd32daa 100644 --- a/core/flyout_metrics_manager.ts +++ b/core/flyout_metrics_manager.ts @@ -73,8 +73,7 @@ export class FlyoutMetricsManager extends MetricsManager { opt_getWorkspaceCoordinates?: boolean, opt_viewMetrics?: ContainerRegion, opt_contentMetrics?: ContainerRegion) { // AnyDuringMigration because: Expected 1 arguments, but got 0. - const contentMetrics = - opt_contentMetrics || (this.getContentMetrics as AnyDuringMigration)(); + const contentMetrics = opt_contentMetrics || this.getContentMetrics(); const margin = this.flyout_.MARGIN * this.workspace_.scale; const scale = opt_getWorkspaceCoordinates ? this.workspace_.scale : 1; diff --git a/core/generator.ts b/core/generator.ts index 53c5ca74d..62d884daf 100644 --- a/core/generator.ts +++ b/core/generator.ts @@ -27,7 +27,7 @@ import type {Workspace} from './workspace.js'; * @alias Blockly.Generator */ export class Generator { - name_: AnyDuringMigration; + name_: string; /** * This is used as a placeholder in functions defined using @@ -36,7 +36,7 @@ export class Generator { * not confuse the regular expression parser. */ protected FUNCTION_NAME_PLACEHOLDER_ = '{leCUI8hutHZI4480Dc}'; - FUNCTION_NAME_PLACEHOLDER_REGEXP_: AnyDuringMigration; + FUNCTION_NAME_PLACEHOLDER_REGEXP_: RegExp; /** * Arbitrary code to inject into locations that risk causing infinite loops. @@ -86,13 +86,13 @@ export class Generator { protected RESERVED_WORDS_ = ''; /** A dictionary of definitions to be printed before the code. */ - protected definitions_?: AnyDuringMigration = undefined; + protected definitions_: {[key: string]: string} = Object.create(null); /** * A dictionary mapping desired function names in definitions_ to actual * function names (to avoid collisions with user functions). */ - protected functionNames_?: AnyDuringMigration = undefined; + protected functionNames_: {[key: string]: string} = Object.create(null); /** A database of variable and procedure names. */ protected nameDB_?: Names = undefined; @@ -118,7 +118,7 @@ export class Generator { 'No workspace specified in workspaceToCode call. Guessing.'); workspace = common.getMainWorkspace(); } - let code = []; + const code = []; this.init(workspace); const blocks = workspace.getTopBlocks(true); for (let i = 0, block; block = blocks[i]; i++) { @@ -132,9 +132,7 @@ export class Generator { if (block.outputConnection) { // This block is a naked value. Ask the language's code generator if // it wants to append a semicolon, or something. - // AnyDuringMigration because: Argument of type 'string | any[]' is - // not assignable to parameter of type 'string'. - line = this.scrubNakedValue(line as AnyDuringMigration); + line = this.scrubNakedValue(line); if (this.STATEMENT_PREFIX && !block.suppressPrefixSuffix) { line = this.injectId(this.STATEMENT_PREFIX, block) + line; } @@ -145,21 +143,14 @@ export class Generator { code.push(line); } } - // AnyDuringMigration because: Type 'string' is not assignable to type - // 'any[]'. // Blank line between each section. - code = code.join('\n') as AnyDuringMigration; - // AnyDuringMigration because: Argument of type 'any[]' is not assignable - // to parameter of type 'string'. AnyDuringMigration because: Type 'string' - // is not assignable to type 'any[]'. - code = this.finish(code as AnyDuringMigration) as AnyDuringMigration; + let codeString = code.join('\n'); + codeString = this.finish(codeString); // Final scrubbing of whitespace. - // AnyDuringMigration because: Property 'replace' does not exist on type - // 'any[]'. - code = (code as AnyDuringMigration).replace(/^\s+\n/, ''); - code = code.replace(/\n\s+$/, '\n'); - code = code.replace(/[ \t]+\n/g, '\n'); - return code; + codeString = codeString.replace(/^\s+\n/, ''); + codeString = codeString.replace(/\n\s+$/, '\n'); + codeString = codeString.replace(/[ \t]+\n/g, '\n'); + return codeString; } // The following are some helpful functions which can be used by multiple @@ -211,7 +202,7 @@ export class Generator { * operator order value. Returns '' if block is null. */ blockToCode(block: Block|null, opt_thisOnly?: boolean): string - |AnyDuringMigration[] { + |[string, number] { if (this.isInitialized === false) { console.warn( 'Generator init was not called before blockToCode was called.'); @@ -228,7 +219,7 @@ export class Generator { return opt_thisOnly ? '' : this.blockToCode(block.getChildren(false)[0]); } - const func = (this as AnyDuringMigration)[block.type]; + const func = (this as any)[block.type]; if (typeof func !== 'function') { throw Error( 'Language "' + this.name_ + '" does not know how to generate ' + @@ -503,8 +494,8 @@ export class Generator { finish(code: string): string { // Optionally override // Clean up temporary data. - delete this.definitions_; - delete this.functionNames_; + this.definitions_ = Object.create(null); + this.functionNames_ = Object.create(null); return code; } @@ -531,8 +522,6 @@ Object.defineProperties(Generator.prototype, { * @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021). * @suppress {checkTypes} */ - // AnyDuringMigration because: Type 'Names | undefined' is not assignable to - // type 'PropertyDescriptor'. variableDB_: ({ /** @returns Name database. */ get(this: Generator): Names | diff --git a/core/keyboard_nav/basic_cursor.ts b/core/keyboard_nav/basic_cursor.ts index 434784587..648158fc6 100644 --- a/core/keyboard_nav/basic_cursor.ts +++ b/core/keyboard_nav/basic_cursor.ts @@ -120,9 +120,7 @@ export class BasicCursor extends Cursor { return this.getNextNode_(newNode, isValid); } const siblingOrParent = this.findSiblingOrParent_(node.out()); - // AnyDuringMigration because: Argument of type 'ASTNode | null' is not - // assignable to parameter of type 'ASTNode'. - if (isValid(siblingOrParent as AnyDuringMigration)) { + if (isValid(siblingOrParent)) { return siblingOrParent; } else if (siblingOrParent) { return this.getNextNode_(siblingOrParent, isValid); diff --git a/core/menu.ts b/core/menu.ts index 1dc5d7dea..f5c46e076 100644 --- a/core/menu.ts +++ b/core/menu.ts @@ -123,7 +123,7 @@ export class Menu { * @returns The DOM element. * @internal */ - getElement(): Element|null { + getElement(): HTMLDivElement|null { return this.element_; } @@ -135,9 +135,7 @@ export class Menu { focus() { const el = this.getElement(); if (el) { - // AnyDuringMigration because: Property 'focus' does not exist on type - // 'Element'. - (el as AnyDuringMigration).focus({preventScroll: true}); + el.focus({preventScroll: true}); dom.addClass(el, 'blocklyFocused'); } } @@ -146,9 +144,7 @@ export class Menu { private blur_() { const el = this.getElement(); if (el) { - // AnyDuringMigration because: Property 'blur' does not exist on type - // 'Element'. - (el as AnyDuringMigration).blur(); + el.blur(); dom.removeClass(el, 'blocklyFocused'); } } @@ -209,8 +205,9 @@ export class Menu { // a menu item's div, or some element within the menu item. // Walk up parents until one meets either the menu's root element, or // a menu item's div. - while (elem && elem !== menuElem) { - if (dom.hasClass(elem, 'blocklyMenuItem')) { + let currentElement: Element|null = elem; + while (currentElement && currentElement !== menuElem) { + if (dom.hasClass(currentElement, 'blocklyMenuItem')) { // Having found a menu item's div, locate that menu item in this menu. for (let i = 0, menuItem; menuItem = this.menuItems_[i]; i++) { if (menuItem.getElement() === elem) { @@ -218,9 +215,7 @@ export class Menu { } } } - // AnyDuringMigration because: Type 'HTMLElement | null' is not - // assignable to type 'Element'. - elem = elem.parentElement as AnyDuringMigration; + currentElement = currentElement.parentElement; } return null; } @@ -258,10 +253,9 @@ export class Menu { * @internal */ highlightNext() { - // AnyDuringMigration because: Argument of type 'MenuItem | null' is not - // assignable to parameter of type 'MenuItem'. - const index = - this.menuItems_.indexOf(this.highlightedItem_ as AnyDuringMigration); + const index = this.highlightedItem_ ? + this.menuItems_.indexOf(this.highlightedItem_) : + -1; this.highlightHelper_(index, 1); } @@ -272,10 +266,9 @@ export class Menu { * @internal */ highlightPrevious() { - // AnyDuringMigration because: Argument of type 'MenuItem | null' is not - // assignable to parameter of type 'MenuItem'. - const index = - this.menuItems_.indexOf(this.highlightedItem_ as AnyDuringMigration); + const index = this.highlightedItem_ ? + this.menuItems_.indexOf(this.highlightedItem_) : + -1; this.highlightHelper_(index < 0 ? this.menuItems_.length : index, -1); } diff --git a/core/menuitem.ts b/core/menuitem.ts index 6af0ff84e..3eec5ac69 100644 --- a/core/menuitem.ts +++ b/core/menuitem.ts @@ -135,8 +135,8 @@ export class MenuItem { * @returns value Value associated with the menu item. * @internal */ - getValue(): AnyDuringMigration { - return this.opt_value; + getValue(): string|null { + return this.opt_value ?? null; } /** @@ -245,7 +245,7 @@ export class MenuItem { * @param obj Used as the 'this' object in fn when called. * @internal */ - onAction(fn: (p1: MenuItem) => AnyDuringMigration, obj: AnyDuringMigration) { + onAction(fn: (p1: MenuItem) => void, obj: object) { this.actionHandler_ = fn.bind(obj); } } diff --git a/core/mutator.ts b/core/mutator.ts index 11843577f..a29520b92 100644 --- a/core/mutator.ts +++ b/core/mutator.ts @@ -71,10 +71,10 @@ export class Mutator extends Icon { private sourceListener_: Function|null = null; /** - * The PID associated with the updateWorkpace_ timeout, or 0 if no timeout + * The PID associated with the updateWorkpace_ timeout, or null if no timeout * is currently running. */ - private updateWorkspacePid_: AnyDuringMigration = 0; + private updateWorkspacePid_: ReturnType|null = null; /** @param quarkNames List of names of sub-blocks for flyout. */ constructor(block: BlockSvg, quarkNames: string[]) { @@ -382,7 +382,7 @@ export class Mutator extends Icon { private workspaceChanged_(e: Abstract) { if (!this.shouldIgnoreMutatorEvent_(e) && !this.updateWorkspacePid_) { this.updateWorkspacePid_ = setTimeout(() => { - this.updateWorkspacePid_ = 0; + this.updateWorkspacePid_ = null; this.updateWorkspace_(); }, 0); } diff --git a/core/procedures.ts b/core/procedures.ts index fe3cc4016..608ab24bf 100644 --- a/core/procedures.ts +++ b/core/procedures.ts @@ -50,6 +50,8 @@ export const CATEGORY_NAME = 'PROCEDURE'; */ export const DEFAULT_ARG = 'x'; +export type ProcedureTuple = [string, string[], boolean]; + /** * Procedure block type. * @@ -57,8 +59,8 @@ export const DEFAULT_ARG = 'x'; */ export interface ProcedureBlock { getProcedureCall: () => string; - renameProcedure: (p1: string, p2: string) => AnyDuringMigration; - getProcedureDef: () => AnyDuringMigration[]; + renameProcedure: (p1: string, p2: string) => void; + getProcedureDef: () => ProcedureTuple; } /** @@ -70,7 +72,8 @@ export interface ProcedureBlock { * list of name, parameter list, and return value boolean. * @alias Blockly.Procedures.allProcedures */ -export function allProcedures(root: Workspace): AnyDuringMigration[][][] { +export function allProcedures(root: Workspace): + [ProcedureTuple[], ProcedureTuple[]] { const proceduresNoReturn = root.getBlocksByType('procedures_defnoreturn', false) .map(function(block) { @@ -93,8 +96,7 @@ export function allProcedures(root: Workspace): AnyDuringMigration[][][] { * @param tb Second tuple. * @returns -1, 0, or 1 to signify greater than, equality, or less than. */ -function procTupleComparator( - ta: AnyDuringMigration[], tb: AnyDuringMigration[]): number { +function procTupleComparator(ta: ProcedureTuple, tb: ProcedureTuple): number { return ta[0].localeCompare(tb[0], undefined, {sensitivity: 'base'}); } @@ -212,9 +214,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { // const block = utilsXml.createElement('block'); block.setAttribute('type', 'procedures_defnoreturn'); - // AnyDuringMigration because: Argument of type 'number' is not assignable - // to parameter of type 'string'. - block.setAttribute('gap', 16 as AnyDuringMigration); + block.setAttribute('gap', '16'); const nameField = utilsXml.createElement('field'); nameField.setAttribute('name', 'NAME'); nameField.appendChild( @@ -228,9 +228,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { // const block = utilsXml.createElement('block'); block.setAttribute('type', 'procedures_defreturn'); - // AnyDuringMigration because: Argument of type 'number' is not assignable - // to parameter of type 'string'. - block.setAttribute('gap', 16 as AnyDuringMigration); + block.setAttribute('gap', '16'); const nameField = utilsXml.createElement('field'); nameField.setAttribute('name', 'NAME'); nameField.appendChild( @@ -242,16 +240,12 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { // const block = utilsXml.createElement('block'); block.setAttribute('type', 'procedures_ifreturn'); - // AnyDuringMigration because: Argument of type 'number' is not assignable - // to parameter of type 'string'. - block.setAttribute('gap', 16 as AnyDuringMigration); + block.setAttribute('gap', '16'); xmlList.push(block); } if (xmlList.length) { // Add slightly larger gap between system blocks and user calls. - // AnyDuringMigration because: Argument of type 'number' is not assignable - // to parameter of type 'string'. - xmlList[xmlList.length - 1].setAttribute('gap', 24 as AnyDuringMigration); + xmlList[xmlList.length - 1].setAttribute('gap', '24'); } /** @@ -262,7 +256,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { * @param templateName The type of the block to generate. */ function populateProcedures( - procedureList: AnyDuringMigration[][], templateName: string) { + procedureList: ProcedureTuple[], templateName: string) { for (let i = 0; i < procedureList.length; i++) { const name = procedureList[i][0]; const args = procedureList[i][1]; @@ -273,9 +267,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { // const block = utilsXml.createElement('block'); block.setAttribute('type', templateName); - // AnyDuringMigration because: Argument of type 'number' is not - // assignable to parameter of type 'string'. - block.setAttribute('gap', 16 as AnyDuringMigration); + block.setAttribute('gap', '16'); const mutation = utilsXml.createElement('mutation'); mutation.setAttribute('name', name); block.appendChild(mutation); @@ -288,9 +280,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { } } - // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not - // assignable to parameter of type 'Workspace'. - const tuple = allProcedures(workspace as AnyDuringMigration); + const tuple = allProcedures(workspace); populateProcedures(tuple[0], 'procedures_callnoreturn'); populateProcedures(tuple[1], 'procedures_callreturn'); return xmlList; diff --git a/core/utils.ts b/core/utils.ts index 25558d400..8a0fd767a 100644 --- a/core/utils.ts +++ b/core/utils.ts @@ -76,9 +76,7 @@ export { * @alias Blockly.utils.noEvent */ export function noEvent(e: Event) { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn('Blockly.utils.noEvent', 'September 2021', 'September 2022'); + deprecation.warn('Blockly.utils.noEvent', 'September 2021', 'September 2022'); // This event has been handled. No need to bubble up to the document. e.preventDefault(); e.stopPropagation(); @@ -93,11 +91,9 @@ export function noEvent(e: Event) { * @alias Blockly.utils.isTargetInput */ export function isTargetInput(e: Event): boolean { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.isTargetInput', 'September 2021', 'September 2022', - 'Blockly.browserEvents.isTargetInput'); + deprecation.warn( + 'Blockly.utils.isTargetInput', 'September 2021', 'September 2022', + 'Blockly.browserEvents.isTargetInput'); return browserEvents.isTargetInput(e); } @@ -111,14 +107,10 @@ export function isTargetInput(e: Event): boolean { * @alias Blockly.utils.getRelativeXY */ export function getRelativeXY(element: Element): Coordinate { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getRelativeXY', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.getRelativeXY'); - // AnyDuringMigration because: Property 'getRelativeXY' does not exist on - // type 'void'. - return (svgMath as AnyDuringMigration).getRelativeXY(element); + deprecation.warn( + 'Blockly.utils.getRelativeXY', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.getRelativeXY'); + return svgMath.getRelativeXY(element); } /** @@ -132,14 +124,10 @@ export function getRelativeXY(element: Element): Coordinate { * @alias Blockly.utils.getInjectionDivXY_ */ function getInjectionDivXY(element: Element): Coordinate { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getInjectionDivXY_', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.getInjectionDivXY'); - // AnyDuringMigration because: Property 'getInjectionDivXY' does not exist on - // type 'void'. - return (svgMath as AnyDuringMigration).getInjectionDivXY(element); + deprecation.warn( + 'Blockly.utils.getInjectionDivXY_', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.getInjectionDivXY'); + return svgMath.getInjectionDivXY(element); } export const getInjectionDivXY_ = getInjectionDivXY; @@ -152,11 +140,9 @@ export const getInjectionDivXY_ = getInjectionDivXY; * @alias Blockly.utils.isRightButton */ export function isRightButton(e: Event): boolean { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.isRightButton', 'September 2021', 'September 2022', - 'Blockly.browserEvents.isRightButton'); + deprecation.warn( + 'Blockly.utils.isRightButton', 'September 2021', 'September 2022', + 'Blockly.browserEvents.isRightButton'); return browserEvents.isRightButton(e as MouseEvent); } @@ -173,11 +159,9 @@ export function isRightButton(e: Event): boolean { */ export function mouseToSvg( e: Event, svg: SVGSVGElement, matrix: SVGMatrix|null): SVGPoint { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.mouseToSvg', 'September 2021', 'September 2022', - 'Blockly.browserEvents.mouseToSvg'); + deprecation.warn( + 'Blockly.utils.mouseToSvg', 'September 2021', 'September 2022', + 'Blockly.browserEvents.mouseToSvg'); return browserEvents.mouseToSvg(e as MouseEvent, svg, matrix); } @@ -190,11 +174,9 @@ export function mouseToSvg( * @alias Blockly.utils.getScrollDeltaPixels */ export function getScrollDeltaPixels(e: WheelEvent): {x: number, y: number} { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getScrollDeltaPixels', 'September 2021', - 'September 2022', 'Blockly.browserEvents.getScrollDeltaPixels'); + deprecation.warn( + 'Blockly.utils.getScrollDeltaPixels', 'September 2021', 'September 2022', + 'Blockly.browserEvents.getScrollDeltaPixels'); return browserEvents.getScrollDeltaPixels(e); } @@ -212,14 +194,10 @@ export function getScrollDeltaPixels(e: WheelEvent): {x: number, y: number} { * @alias Blockly.utils.tokenizeInterpolation */ export function tokenizeInterpolation(message: string): Array { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.tokenizeInterpolation', 'December 2021', - 'December 2022', 'Blockly.utils.parsing.tokenizeInterpolation'); - // AnyDuringMigration because: Property 'tokenizeInterpolation' does not - // exist on type 'void'. - return (parsing as AnyDuringMigration).tokenizeInterpolation(message); + deprecation.warn( + 'Blockly.utils.tokenizeInterpolation', 'December 2021', 'December 2022', + 'Blockly.utils.parsing.tokenizeInterpolation'); + return parsing.tokenizeInterpolation(message); } /** @@ -233,16 +211,11 @@ export function tokenizeInterpolation(message: string): Array { * @deprecated * @alias Blockly.utils.replaceMessageReferences */ -export function replaceMessageReferences(message: string| - AnyDuringMigration): string { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.replaceMessageReferences', 'December 2021', - 'December 2022', 'Blockly.utils.parsing.replaceMessageReferences'); - // AnyDuringMigration because: Property 'replaceMessageReferences' does not - // exist on type 'void'. - return (parsing as AnyDuringMigration).replaceMessageReferences(message); +export function replaceMessageReferences(message: string|any): string { + deprecation.warn( + 'Blockly.utils.replaceMessageReferences', 'December 2021', + 'December 2022', 'Blockly.utils.parsing.replaceMessageReferences'); + return parsing.replaceMessageReferences(message); } /** @@ -256,14 +229,10 @@ export function replaceMessageReferences(message: string| * @alias Blockly.utils.checkMessageReferences */ export function checkMessageReferences(message: string): boolean { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.checkMessageReferences', 'December 2021', - 'December 2022', 'Blockly.utils.parsing.checkMessageReferences'); - // AnyDuringMigration because: Property 'checkMessageReferences' does not - // exist on type 'void'. - return (parsing as AnyDuringMigration).checkMessageReferences(message); + deprecation.warn( + 'Blockly.utils.checkMessageReferences', 'December 2021', 'December 2022', + 'Blockly.utils.parsing.checkMessageReferences'); + return parsing.checkMessageReferences(message); } /** @@ -274,14 +243,10 @@ export function checkMessageReferences(message: string): boolean { * @alias Blockly.utils.genUid */ export function genUid(): string { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.genUid', 'September 2021', 'September 2022', - 'Blockly.utils.idGenerator.genUid'); - // AnyDuringMigration because: Property 'genUid' does not exist on type - // 'void'. - return (idGenerator as AnyDuringMigration).genUid(); + deprecation.warn( + 'Blockly.utils.genUid', 'September 2021', 'September 2022', + 'Blockly.utils.idGenerator.genUid'); + return idGenerator.genUid(); } /** @@ -293,14 +258,10 @@ export function genUid(): string { * @alias Blockly.utils.is3dSupported */ export function is3dSupported(): boolean { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.is3dSupported', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.is3dSupported'); - // AnyDuringMigration because: Property 'is3dSupported' does not exist on - // type 'void'. - return (svgMath as AnyDuringMigration).is3dSupported(); + deprecation.warn( + 'Blockly.utils.is3dSupported', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.is3dSupported'); + return svgMath.is3dSupported(); } /** @@ -314,14 +275,10 @@ export function is3dSupported(): boolean { * @internal */ export function getViewportBBox(): Rect { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getViewportBBox', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.getViewportBBox'); - // AnyDuringMigration because: Property 'getViewportBBox' does not exist on - // type 'void'. - return (svgMath as AnyDuringMigration).getViewportBBox(); + deprecation.warn( + 'Blockly.utils.getViewportBBox', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.getViewportBBox'); + return svgMath.getViewportBBox(); } /** @@ -334,11 +291,9 @@ export function getViewportBBox(): Rect { * @deprecated * @internal */ -export function arrayRemove( - arr: AnyDuringMigration[], value: AnyDuringMigration): boolean { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn('Blockly.utils.arrayRemove', 'December 2021', 'December 2022'); +export function arrayRemove(arr: Array, value: T): boolean { + deprecation.warn( + 'Blockly.utils.arrayRemove', 'December 2021', 'December 2022'); return arrayUtils.removeElem(arr, value); } @@ -351,14 +306,10 @@ export function arrayRemove( * @alias Blockly.utils.getDocumentScroll */ export function getDocumentScroll(): Coordinate { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getDocumentScroll', 'December 2021', 'December 2022', - 'Blockly.utils.svgMath.getDocumentScroll'); - // AnyDuringMigration because: Property 'getDocumentScroll' does not exist on - // type 'void'. - return (svgMath as AnyDuringMigration).getDocumentScroll(); + deprecation.warn( + 'Blockly.utils.getDocumentScroll', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.getDocumentScroll'); + return svgMath.getDocumentScroll(); } /** @@ -373,12 +324,10 @@ export function getDocumentScroll(): Coordinate { * @alias Blockly.utils.getBlockTypeCounts */ export function getBlockTypeCounts( - block: Block, opt_stripFollowing?: boolean): AnyDuringMigration { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.getBlockTypeCounts', 'December 2021', 'December 2022', - 'Blockly.common.getBlockTypeCounts'); + block: Block, opt_stripFollowing?: boolean): {[key: string]: number} { + deprecation.warn( + 'Blockly.utils.getBlockTypeCounts', 'December 2021', 'December 2022', + 'Blockly.common.getBlockTypeCounts'); return common.getBlockTypeCounts(block, opt_stripFollowing); } @@ -393,15 +342,10 @@ export function getBlockTypeCounts( */ export function screenToWsCoordinates( ws: WorkspaceSvg, screenCoordinates: Coordinate): Coordinate { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.screenToWsCoordinates', 'December 2021', - 'December 2022', 'Blockly.utils.svgMath.screenToWsCoordinates'); - // AnyDuringMigration because: Property 'screenToWsCoordinates' does not - // exist on type 'void'. - return (svgMath as AnyDuringMigration) - .screenToWsCoordinates(ws, screenCoordinates); + deprecation.warn( + 'Blockly.utils.screenToWsCoordinates', 'December 2021', 'December 2022', + 'Blockly.utils.svgMath.screenToWsCoordinates'); + return svgMath.screenToWsCoordinates(ws, screenCoordinates); } /** @@ -418,14 +362,10 @@ export function screenToWsCoordinates( */ export function parseBlockColour(colour: number| string): {hue: number|null, hex: string} { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn( - 'Blockly.utils.parseBlockColour', 'December 2021', 'December 2022', - 'Blockly.utils.parsing.parseBlockColour'); - // AnyDuringMigration because: Property 'parseBlockColour' does not exist on - // type 'void'. - return (parsing as AnyDuringMigration).parseBlockColour(colour); + deprecation.warn( + 'Blockly.utils.parseBlockColour', 'December 2021', 'December 2022', + 'Blockly.utils.parsing.parseBlockColour'); + return parsing.parseBlockColour(colour); } /** @@ -436,9 +376,8 @@ export function parseBlockColour(colour: number| * @deprecated * @alias Blockly.utils.runAfterPageLoad */ -export function runAfterPageLoad(fn: () => AnyDuringMigration) { - // AnyDuringMigration because: Property 'warn' does not exist on type 'void'. - (deprecation as AnyDuringMigration) - .warn('Blockly.utils.runAfterPageLoad', 'December 2021', 'December 2022'); +export function runAfterPageLoad(fn: () => void) { + deprecation.warn( + 'Blockly.utils.runAfterPageLoad', 'December 2021', 'December 2022'); extensions.runAfterPageLoad(fn); } diff --git a/core/utils/aria.ts b/core/utils/aria.ts index b0bed04a5..fcacf4da7 100644 --- a/core/utils/aria.ts +++ b/core/utils/aria.ts @@ -152,7 +152,5 @@ export function setState( value = value.join(' '); } const attrStateName = ARIA_PREFIX + stateName; - // AnyDuringMigration because: Argument of type 'string | number | boolean' - // is not assignable to parameter of type 'string'. - element.setAttribute(attrStateName, value as AnyDuringMigration); + element.setAttribute(attrStateName, `${value}`); } diff --git a/core/utils/array.ts b/core/utils/array.ts index 59002188c..26cda7961 100644 --- a/core/utils/array.ts +++ b/core/utils/array.ts @@ -18,8 +18,7 @@ goog.declareModuleId('Blockly.utils.array'); * @alias Blockly.array.removeElem * @internal */ -export function removeElem( - arr: AnyDuringMigration[], value: AnyDuringMigration): boolean { +export function removeElem(arr: Array, value: T): boolean { const i = arr.indexOf(value); if (i === -1) { return false; diff --git a/core/utils/idgenerator.ts b/core/utils/idgenerator.ts index 92b580fc9..4fe0aa67c 100644 --- a/core/utils/idgenerator.ts +++ b/core/utils/idgenerator.ts @@ -12,6 +12,15 @@ import * as goog from '../../closure/goog/goog.js'; goog.declareModuleId('Blockly.utils.idGenerator'); +/** + * Legal characters for the universally unique IDs. Should be all on + * a US keyboard. No characters that conflict with XML or JSON. + * Requests to remove additional 'problematic' characters from this + * soup will be denied. That's your failure to properly escape in + * your own environment. Issues #251, #625, #682, #1304. + */ +const soup = '!#$%()*+,-./:;=?@[]^_`{|}~' + + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; /** * Namespace object for internal implementations we want to be able to @@ -19,7 +28,23 @@ goog.declareModuleId('Blockly.utils.idGenerator'); * * @ignore */ -const internal = {}; +const internal = { + /** + * Generate a random unique ID. This should be globally unique. + * 87 characters ^ 20 length > 128 bits (better than a UUID). + * + * @returns A globally unique ID string. + */ + genUid: () => { + const length = 20; + const soupLength = soup.length; + const id = []; + for (let i = 0; i < length; i++) { + id[i] = soup.charAt(Math.random() * soupLength); + } + return id.join(''); + }, +}; export const TEST_ONLY = internal; /** Next unique ID to use. */ @@ -40,33 +65,6 @@ export function getNextUniqueId(): string { return 'blockly-' + (nextId++).toString(36); } -/** - * Legal characters for the universally unique IDs. Should be all on - * a US keyboard. No characters that conflict with XML or JSON. - * Requests to remove additional 'problematic' characters from this - * soup will be denied. That's your failure to properly escape in - * your own environment. Issues #251, #625, #682, #1304. - */ -const soup = '!#$%()*+,-./:;=?@[]^_`{|}~' + - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - -/** - * Generate a random unique ID. This should be globally unique. - * 87 characters ^ 20 length > 128 bits (better than a UUID). - * - * @returns A globally unique ID string. - */ -// AnyDuringMigration because: Property 'genUid' does not exist on type '{}'. -(internal as AnyDuringMigration).genUid = function(): string { - const length = 20; - const soupLength = soup.length; - const id = []; - for (let i = 0; i < length; i++) { - id[i] = soup.charAt(Math.random() * soupLength); - } - return id.join(''); -}; - /** * Generate a random unique ID. * @@ -75,6 +73,5 @@ const soup = '!#$%()*+,-./:;=?@[]^_`{|}~' + * @alias Blockly.utils.idGenerator.genUid */ export function genUid(): string { - // AnyDuringMigration because: Property 'genUid' does not exist on type '{}'. - return (internal as AnyDuringMigration).genUid(); + return internal.genUid(); } diff --git a/core/utils/parsing.ts b/core/utils/parsing.ts index 1034bfa45..36452f0d7 100644 --- a/core/utils/parsing.ts +++ b/core/utils/parsing.ts @@ -183,8 +183,7 @@ export function tokenizeInterpolation(message: string): (string|number)[] { * @returns String with message references replaced. * @alias Blockly.utils.parsing.replaceMessageReferences */ -export function replaceMessageReferences(message: string| - AnyDuringMigration): string { +export function replaceMessageReferences(message: string|any): string { if (typeof message !== 'string') { return message; } diff --git a/core/variables.ts b/core/variables.ts index 166f46d17..16f762b1a 100644 --- a/core/variables.ts +++ b/core/variables.ts @@ -82,11 +82,10 @@ export function allDeveloperVariables(workspace: Workspace): string[] { const variables = new Set(); for (let i = 0, block; block = blocks[i]; i++) { let getDeveloperVariables = block.getDeveloperVariables; - if (!getDeveloperVariables && - (block as AnyDuringMigration).getDeveloperVars) { + if (!getDeveloperVariables && (block as any).getDeveloperVars) { // August 2018: getDeveloperVars() was deprecated and renamed // getDeveloperVariables(). - getDeveloperVariables = (block as AnyDuringMigration).getDeveloperVars; + getDeveloperVariables = (block as any).getDeveloperVars; if (!ALL_DEVELOPER_VARS_WARNINGS_BY_BLOCK_TYPE[block.type]) { console.warn( 'Function getDeveloperVars() deprecated. Use ' + @@ -120,17 +119,12 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { button.setAttribute('callbackKey', 'CREATE_VARIABLE'); workspace.registerButtonCallback('CREATE_VARIABLE', function(button) { - // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not - // assignable to parameter of type 'Workspace'. - createVariableButtonHandler( - button.getTargetWorkspace() as AnyDuringMigration); + createVariableButtonHandler(button.getTargetWorkspace()); }); xmlList.push(button); - // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not - // assignable to parameter of type 'Workspace'. - const blockList = flyoutCategoryBlocks(workspace as AnyDuringMigration); + const blockList = flyoutCategoryBlocks(workspace); xmlList = xmlList.concat(blockList); return xmlList; } @@ -152,27 +146,15 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { if (Blocks['variables_set']) { const block = utilsXml.createElement('block'); block.setAttribute('type', 'variables_set'); - // AnyDuringMigration because: Argument of type 'number' is not - // assignable to parameter of type 'string'. - block.setAttribute( - 'gap', (Blocks['math_change'] ? 8 : 24) as AnyDuringMigration); - // AnyDuringMigration because: Argument of type 'Element | null' is not - // assignable to parameter of type 'Node'. - block.appendChild( - generateVariableFieldDom(mostRecentVariable) as AnyDuringMigration); + block.setAttribute('gap', Blocks['math_change'] ? '8' : '24'); + block.appendChild(generateVariableFieldDom(mostRecentVariable)); xmlList.push(block); } if (Blocks['math_change']) { const block = utilsXml.createElement('block'); block.setAttribute('type', 'math_change'); - // AnyDuringMigration because: Argument of type 'number' is not - // assignable to parameter of type 'string'. - block.setAttribute( - 'gap', (Blocks['variables_get'] ? 20 : 8) as AnyDuringMigration); - // AnyDuringMigration because: Argument of type 'Element | null' is not - // assignable to parameter of type 'Node'. - block.appendChild( - generateVariableFieldDom(mostRecentVariable) as AnyDuringMigration); + block.setAttribute('gap', Blocks['variables_get'] ? '20' : '8'); + block.appendChild(generateVariableFieldDom(mostRecentVariable)); const value = Xml.textToDom( '' + '' + @@ -188,13 +170,8 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { for (let i = 0, variable; variable = variableModelList[i]; i++) { const block = utilsXml.createElement('block'); block.setAttribute('type', 'variables_get'); - // AnyDuringMigration because: Argument of type 'number' is not - // assignable to parameter of type 'string'. - block.setAttribute('gap', 8 as AnyDuringMigration); - // AnyDuringMigration because: Argument of type 'Element | null' is not - // assignable to parameter of type 'Node'. - block.appendChild( - generateVariableFieldDom(variable) as AnyDuringMigration); + block.setAttribute('gap', '8'); + block.appendChild(generateVariableFieldDom(variable)); xmlList.push(block); } } @@ -265,9 +242,7 @@ export function generateUniqueNameFromOptions( if (letterIndex === letters.length) { // Reached the end of the character sequence so back to 'i'. letterIndex = 0; - // AnyDuringMigration because: Type 'number' is not assignable to type - // 'string'. - suffix = (Number(suffix) + 1) as AnyDuringMigration; + suffix = `${Number(suffix) + 1}`; } potName = letters.charAt(letterIndex) + suffix; } @@ -291,12 +266,11 @@ export function generateUniqueNameFromOptions( * @alias Blockly.Variables.createVariableButtonHandler */ export function createVariableButtonHandler( - workspace: Workspace, - opt_callback?: (p1?: string|null) => AnyDuringMigration, + workspace: Workspace, opt_callback?: (p1?: string|null) => void, opt_type?: string) { const type = opt_type || ''; // This function needs to be named so it can be called recursively. - function promptAndCheckWithAlert(defaultName: AnyDuringMigration) { + function promptAndCheckWithAlert(defaultName: string) { promptName(Msg['NEW_VARIABLE_TITLE'], defaultName, function(text) { if (text) { const existing = nameUsedWithAnyType(text, workspace); @@ -343,9 +317,9 @@ export function createVariableButtonHandler( */ export function renameVariable( workspace: Workspace, variable: VariableModel, - opt_callback?: (p1?: string|null) => AnyDuringMigration) { + opt_callback?: (p1?: string|null) => void) { // This function needs to be named so it can be called recursively. - function promptAndCheckWithAlert(defaultName: AnyDuringMigration) { + function promptAndCheckWithAlert(defaultName: string) { const promptText = Msg['RENAME_VARIABLE_TITLE'].replace('%1', variable.name); promptName(promptText, defaultName, function(newName) { @@ -381,13 +355,13 @@ export function renameVariable( * * @param promptText The string of the prompt. * @param defaultText The default value to show in the prompt's field. - * @param callback A callback. It will return the new variable name, or null if - * the user picked something illegal. + * @param callback A callback. It will be passed the new variable name, or null + * if the user picked something illegal. * @alias Blockly.Variables.promptName */ export function promptName( promptText: string, defaultText: string, - callback: (p1: string|null) => AnyDuringMigration) { + callback: (p1: string|null) => void) { dialog.prompt(promptText, defaultText, function(newVar) { // Merge runs of whitespace. Strip leading and trailing whitespace. // Beyond this, all names are legal. @@ -452,8 +426,8 @@ export function nameUsedWithAnyType( * @returns The generated DOM. * @alias Blockly.Variables.generateVariableFieldDom */ -export function generateVariableFieldDom(variableModel: VariableModel): Element| - null { +export function generateVariableFieldDom(variableModel: VariableModel): + Element { /* Generates the following XML: * foo */ @@ -556,10 +530,7 @@ function createVariable( const ws = (workspace.isFlyout ? (workspace as WorkspaceSvg).targetWorkspace : workspace); - // Must call version on exports to allow for mocking in tests. See #5321 - // AnyDuringMigration because: Argument of type 'Workspace | WorkspaceSvg' - // is not assignable to parameter of type 'Workspace'. - opt_name = generateUniqueName(ws as AnyDuringMigration); + opt_name = generateUniqueName(ws!); } // Create a potential variable if in the flyout. diff --git a/core/variables_dynamic.ts b/core/variables_dynamic.ts index 0b00bf328..6191b99d2 100644 --- a/core/variables_dynamic.ts +++ b/core/variables_dynamic.ts @@ -19,6 +19,7 @@ import {VariableModel} from './variable_model.js'; import * as Variables from './variables.js'; import type {Workspace} from './workspace.js'; import type {WorkspaceSvg} from './workspace_svg.js'; +import type {FlyoutButton} from './flyout_button.js'; /** @@ -37,7 +38,7 @@ export const CATEGORY_NAME = 'VARIABLE_DYNAMIC'; * * @param button */ -function stringButtonClickHandler(button: AnyDuringMigration) { +function stringButtonClickHandler(button: FlyoutButton) { Variables.createVariableButtonHandler( button.getTargetWorkspace(), undefined, 'String'); } @@ -49,7 +50,7 @@ export const onCreateVariableButtonClick_String = stringButtonClickHandler; * * @param button */ -function numberButtonClickHandler(button: AnyDuringMigration) { +function numberButtonClickHandler(button: FlyoutButton) { Variables.createVariableButtonHandler( button.getTargetWorkspace(), undefined, 'Number'); } @@ -61,7 +62,7 @@ export const onCreateVariableButtonClick_Number = numberButtonClickHandler; * * @param button */ -function colourButtonClickHandler(button: AnyDuringMigration) { +function colourButtonClickHandler(button: FlyoutButton) { Variables.createVariableButtonHandler( button.getTargetWorkspace(), undefined, 'Colour'); } @@ -98,9 +99,7 @@ export function flyoutCategory(workspace: WorkspaceSvg): Element[] { workspace.registerButtonCallback( 'CREATE_VARIABLE_COLOUR', colourButtonClickHandler); - // AnyDuringMigration because: Argument of type 'WorkspaceSvg' is not - // assignable to parameter of type 'Workspace'. - const blockList = flyoutCategoryBlocks(workspace as AnyDuringMigration); + const blockList = flyoutCategoryBlocks(workspace); xmlList = xmlList.concat(blockList); return xmlList; } @@ -121,14 +120,8 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { const firstVariable = variableModelList[variableModelList.length - 1]; const block = xml.createElement('block'); block.setAttribute('type', 'variables_set_dynamic'); - // AnyDuringMigration because: Argument of type 'number' is not - // assignable to parameter of type 'string'. - block.setAttribute('gap', 24 as AnyDuringMigration); - // AnyDuringMigration because: Argument of type 'Element | null' is not - // assignable to parameter of type 'Node'. - block.appendChild( - Variables.generateVariableFieldDom(firstVariable) as - AnyDuringMigration); + block.setAttribute('gap', '24'); + block.appendChild(Variables.generateVariableFieldDom(firstVariable)); xmlList.push(block); } if (Blocks['variables_get_dynamic']) { @@ -136,13 +129,8 @@ export function flyoutCategoryBlocks(workspace: Workspace): Element[] { for (let i = 0, variable; variable = variableModelList[i]; i++) { const block = xml.createElement('block'); block.setAttribute('type', 'variables_get_dynamic'); - // AnyDuringMigration because: Argument of type 'number' is not - // assignable to parameter of type 'string'. - block.setAttribute('gap', 8 as AnyDuringMigration); - // AnyDuringMigration because: Argument of type 'Element | null' is not - // assignable to parameter of type 'Node'. - block.appendChild( - Variables.generateVariableFieldDom(variable) as AnyDuringMigration); + block.setAttribute('gap', '8'); + block.appendChild(Variables.generateVariableFieldDom(variable)); xmlList.push(block); } }