Skip to content

Commit 84c666b

Browse files
authored
Fix TS errors (#154)
1 parent 7c998f2 commit 84c666b

File tree

8 files changed

+34
-32
lines changed

8 files changed

+34
-32
lines changed

src/blocks/mrc_component.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import * as ToolboxItems from '../toolbox/items';
3030
import * as CommonStorage from '../storage/common_storage';
3131
import { createPortShadow } from './mrc_port';
3232
import { createNumberShadowValue } from './utils/value';
33+
import { ClassData, FunctionData } from './utils/python_json_types';
34+
3335

3436
export const BLOCK_NAME = 'mrc_component';
3537
export const OUTPUT_NAME = 'mrc_component';
@@ -177,6 +179,7 @@ export function getAllPossibleComponents(hideParams: boolean): ToolboxItems.Cont
177179
const contents: ToolboxItems.ContentsType[] = [];
178180
// Iterate through all the components subclasses and add definition blocks.
179181
const componentTypes = getSubclassNames('component.Component');
182+
180183
componentTypes.forEach(componentType => {
181184
const classData = getClassData(componentType);
182185
if (!classData) {
@@ -212,7 +215,7 @@ function createComponentBlock(
212215
const inputs: {[key: string]: any} = {};
213216
for (let i = 0; i < staticFunctionData.args.length; i++) {
214217
const argData = staticFunctionData.args[i];
215-
extraState.params.push({
218+
extraState.params!.push({
216219
'name': argData.name,
217220
'type': argData.type,
218221
});
@@ -233,14 +236,16 @@ function createComponentBlock(
233236
function getPortTypeForArgument(argName: string): string | null {
234237
const argNameLower = argName.toLowerCase();
235238
const moduleData = getModuleData('component');
236-
for (const enumData of moduleData.enums) {
237-
if (enumData.enumClassName === 'component.PortType') {
238-
for (const value of enumData.enumValues) {
239-
if (argNameLower === value.toLowerCase()) {
240-
return value;
241-
}
242-
}
243-
break;
239+
if (moduleData) {
240+
for (const enumData of moduleData.enums) {
241+
if (enumData.enumClassName === 'component.PortType') {
242+
for (const value of enumData.enumValues) {
243+
if (argNameLower === value.toLowerCase()) {
244+
return value;
245+
}
246+
}
247+
break;
248+
}
244249
}
245250
}
246251

src/blocks/mrc_get_parameter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {ExtendedPythonGenerator} from '../editor/extended_python_generator';
2727
import {createFieldNonEditableText} from '../fields/FieldNonEditableText';
2828
import {MRC_STYLE_VARIABLES} from '../themes/styles';
2929
import {BLOCK_NAME as MRC_CLASS_METHOD_DEF, ClassMethodDefBlock} from './mrc_class_method_def';
30-
import {BLOCK_NAME as MRC_EVENT_HANDLER, EventHandlerBlock} from './mrc_event_handler';
30+
import {BLOCK_NAME as MRC_EVENT_HANDLER } from './mrc_event_handler';
3131
import * as ChangeFramework from './utils/change_framework';
3232

3333

src/blocks/mrc_port.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const pythonFromBlock = function (
6565
return [code, Order.ATOMIC];
6666
}
6767

68-
export function createPortShadow(portType: string, portNum: int) {
68+
export function createPortShadow(portType: string, portNum: Number) {
6969
return {
7070
shadow: {
7171
type: 'mrc_port',

src/blocks/utils/python.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* @author [email protected] (Liz Looney)
2020
*/
2121

22-
import { ClassData, PythonData, organizeVarDataByType, VariableGettersAndSetters } from './python_json_types';
22+
import { ClassData, PythonData, ModuleData, organizeVarDataByType, VariableGettersAndSetters } from './python_json_types';
2323
import { robotPyData } from './robotpy_data';
2424
import { externalSamplesData } from './external_samples_data';
2525

@@ -157,15 +157,15 @@ export function getAlias(type: string): string | null {
157157
// Returns the list of subclass names for the given type.
158158
// For example, if type is 'wpilib.drive.RobotDriveBase', this function will
159159
// return ['wpilib.drive.DifferentialDrive', 'wpilib.drive.MecanumDrive'].
160-
export function getSubclassNames(type: string): string[] | null {
160+
export function getSubclassNames(type: string): string[] {
161161
for (const pythonData of allPythonData) {
162162
for (const className in pythonData.subclasses) {
163163
if (type === className) {
164164
return pythonData.subclasses[className];
165165
}
166166
}
167167
}
168-
return null;
168+
return [];
169169
}
170170

171171
// Returns the array of allowed types for the given string.

src/editor/editor.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ import { GeneratorContext } from './generator_context';
2626
import * as commonStorage from '../storage/common_storage';
2727
import * as mechanismComponentHolder from '../blocks/mrc_mechanism_component_holder';
2828
//import { testAllBlocksInToolbox } from '../toolbox/toolbox_tests';
29-
import { MethodsCategory} from '../toolbox/methods_category';
30-
import { EventsCategory} from '../toolbox/event_category';
29+
import { MethodsCategory } from '../toolbox/methods_category';
30+
import { EventsCategory } from '../toolbox/event_category';
3131
import { getToolboxJSON } from '../toolbox/toolbox';
3232

3333
const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
34-
kind: 'categoryToolbox',
35-
contents: [],
34+
kind: 'categoryToolbox',
35+
contents: [],
3636
};
3737

3838
export class Editor {
39-
private static workspaceIdToEditor: {[key: string]: Editor} = {};
39+
private static workspaceIdToEditor: { [key: string]: Editor } = {};
4040

4141
private blocklyWorkspace: Blockly.WorkspaceSvg;
4242
private generatorContext: GeneratorContext;
@@ -136,14 +136,14 @@ export class Editor {
136136
if (currentModule) {
137137
// Fetch the content for the current module and the robot.
138138
// TODO: Also fetch the content for the mechanisms?
139-
const promises: {[key: string]: Promise<string>} = {}; // key is module path, value is promise of module content.
139+
const promises: { [key: string]: Promise<string> } = {}; // key is module path, value is promise of module content.
140140
promises[this.modulePath] = this.storage.fetchModuleContent(this.modulePath);
141141
if (this.robotPath !== this.modulePath) {
142142
// Also fetch the robot module content. It contains components, etc, that can be used.
143143
promises[this.robotPath] = this.storage.fetchModuleContent(this.robotPath)
144144
}
145145

146-
const moduleContents: {[key: string]: string} = {}; // key is module path, value is module content
146+
const moduleContents: { [key: string]: string } = {}; // key is module path, value is module content
147147
await Promise.all(
148148
Object.entries(promises).map(async ([modulePath, promise]) => {
149149
moduleContents[modulePath] = await promise;
@@ -173,7 +173,7 @@ export class Editor {
173173
if (toolbox != this.toolbox) {
174174
this.toolbox = toolbox;
175175
this.blocklyWorkspace.updateToolbox(toolbox);
176-
// testAllBlocksInToolbox(toolbox);
176+
// testAllBlocksInToolbox(toolbox);
177177
}
178178
}
179179

@@ -220,23 +220,24 @@ export class Editor {
220220
throw new Error('getModuleContent: this.currentModule is null.');
221221
}
222222
const pythonCode = extendedPythonGenerator.mrcWorkspaceToCode(
223-
this.blocklyWorkspace, this.generatorContext);
223+
this.blocklyWorkspace, this.generatorContext);
224224
const exportedBlocks = JSON.stringify(this.generatorContext.getExportedBlocks());
225225
const blocksContent = JSON.stringify(
226-
Blockly.serialization.workspaces.save(this.blocklyWorkspace));
226+
Blockly.serialization.workspaces.save(this.blocklyWorkspace));
227227
const componentsContent = JSON.stringify(this.getComponents());
228228
return commonStorage.makeModuleContent(
229-
this.currentModule, pythonCode, blocksContent, exportedBlocks, componentsContent);
229+
this.currentModule, pythonCode, blocksContent, exportedBlocks, componentsContent);
230230
}
231231

232232
private getComponents(): commonStorage.Component[] {
233233
const components: commonStorage.Component[] = [];
234234
if (this.currentModule?.moduleType === commonStorage.MODULE_TYPE_ROBOT ||
235-
this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM) {
235+
this.currentModule?.moduleType === commonStorage.MODULE_TYPE_MECHANISM) {
236236
// Get the holder block and ask it for the components.
237237
const holderBlocks = this.blocklyWorkspace.getBlocksByType(mechanismComponentHolder.BLOCK_NAME);
238238
holderBlocks.forEach(holderBlock => {
239-
const componentsFromHolder: commonStorage.Component[] = holderBlock.getComponents();
239+
const componentsFromHolder: commonStorage.Component[] =
240+
(holderBlock as mechanismComponentHolder.MechanismComponentHolderBlock).getComponents();
240241
componentsFromHolder.forEach(component => {
241242
components.push(component);
242243
});

src/reactComponents/Tabs.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ import * as Antd from 'antd';
2323
import * as commonStorage from '../storage/common_storage';
2424
import * as I18Next from 'react-i18next';
2525
import {
26-
RobotOutlined,
27-
CodeOutlined,
28-
BlockOutlined,
2926
CloseOutlined,
3027
DeleteOutlined,
3128
CopyOutlined,

src/reactComponents/ThemeModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ const ThemeModal: React.FC<ThemeModalProps> = ({
8989
setSelectedTheme(currentTheme);
9090
onClose();
9191
};
92-
const { token } = Antd.theme.useToken();
9392

9493
return (
9594
<Antd.Modal

src/toolbox/hardware_category.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ function getComponentsBlocks(currentModule: commonStorage.Module, hideParams : b
260260

261261
holderBlocks.forEach(holderBlock => {
262262
const componentsFromHolder: commonStorage.Component[] =
263-
(holderBlock as mechanismComponentHolder.MechanismComponentHolderBlock).getComponents();
263+
(holderBlock as MechanismComponentHolder.MechanismComponentHolderBlock).getComponents();
264264
componentsFromHolder.forEach(component => {
265265
// Get the blocks for this specific component
266266
contents.push({

0 commit comments

Comments
 (0)