Skip to content

Commit

Permalink
fix: TS errors on dependent projects with certain tsconfig settings (g…
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbytechibong committed Aug 23, 2022
1 parent 883d78d commit ac7789e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 37 deletions.
22 changes: 8 additions & 14 deletions core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ export class Block implements IASTNodeLocation, IDeletable {
* @return Text of block.
*/
toString(opt_maxLength?: number, opt_emptyToken?: string): string {
let text = [];
const text = [];
const emptyFieldPlaceholder = opt_emptyToken || '?';

// Temporarily set flag to navigate to all fields.
Expand Down Expand Up @@ -1397,26 +1397,20 @@ export class Block implements IASTNodeLocation, IDeletable {
}

// Join the text array, removing spaces around added parentheses.
// AnyDuringMigration because: Type 'string' is not assignable to type
// 'any[]'.
text = text.reduce(function(acc, value) {
let combinedText: string = text.reduce(function(acc, value) {
return acc + (acc.substr(-1) === '(' || value === ')' ? '' : ' ') + value;
}, '') as AnyDuringMigration;
// AnyDuringMigration because: Property 'trim' does not exist on type
// 'any[]'.
text = (text as AnyDuringMigration).trim() || '???';
}, '');

combinedText = combinedText.trim() || '???';
if (opt_maxLength) {
// TODO: Improve truncation so that text from this block is given
// priority. E.g. "1+2+3+4+5+6+7+8+9=0" should be "...6+7+8+9=0", not
// "1+2+3+4+5...". E.g. "1+2+3+4+5=6+7+8+9+0" should be "...4+5=6+7...".
if (text.length > opt_maxLength) {
// AnyDuringMigration because: Type 'string' is not assignable to type
// 'any[]'.
text = (text.substring(0, opt_maxLength - 3) + '...') as
AnyDuringMigration;
if (combinedText.length > opt_maxLength) {
combinedText = combinedText.substring(0, opt_maxLength - 3) + '...';
}
}
return text;
return combinedText;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/field_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function fromJson(options: AnyDuringMigration): Field|null {
*/
function fromJsonInternal(options: AnyDuringMigration): Field|null {
const fieldObject =
registry.getObject(registry.Type.FIELD, options['type']) as
registry.getObject(registry.Type.FIELD, options['type']) as unknown as
IRegistrableField |
null;
if (!fieldObject) {
Expand Down
20 changes: 6 additions & 14 deletions core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class Generator {
'No workspace specified in workspaceToCode call. Guessing.');
workspace = common.getMainWorkspace();
}
let code = [];
const lines = [];
this.init(workspace);
const blocks = workspace.getTopBlocks(true);
for (let i = 0, block; block = blocks[i]; i++) {
Expand All @@ -144,21 +144,13 @@ export class Generator {
line = line + this.injectId(this.STATEMENT_SUFFIX, block);
}
}
code.push(line);
lines.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;
// Final scrubbing of whitespace.
// AnyDuringMigration because: Property 'replace' does not exist on type
// 'any[]'.
code = (code as AnyDuringMigration).replace(/^\s+\n/, '');

let code = lines.join('\n');
code = this.finish(code);
code = code.replace(/^\s+\n/, '');
code = code.replace(/\n\s+$/, '\n');
code = code.replace(/[ \t]+\n/g, '\n');
return code;
Expand Down
14 changes: 6 additions & 8 deletions core/utils/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,20 +403,18 @@ function addAttributes(node: Node, obj: AnyDuringMigration) {
*/
export function parseToolboxTree(toolboxDef: Element|null|string): Element|
null {
let parsedToolboxDef: Element|null = null;
if (toolboxDef) {
if (typeof toolboxDef !== 'string' && !(toolboxDef instanceof Element)) {
toolboxDef = null;
}
if (typeof toolboxDef === 'string') {
toolboxDef = Xml.textToDom(toolboxDef);
if (toolboxDef.nodeName.toLowerCase() !== 'xml') {
parsedToolboxDef = Xml.textToDom(toolboxDef);
if (parsedToolboxDef.nodeName.toLowerCase() !== 'xml') {
throw TypeError('Toolbox should be an <xml> document.');
}
} else if (toolboxDef instanceof Element) {
parsedToolboxDef = toolboxDef;
}
} else {
toolboxDef = null;
}
return toolboxDef;
return parsedToolboxDef;
}

export const TEST_ONLY = {
Expand Down

0 comments on commit ac7789e

Please sign in to comment.