Skip to content

Commit

Permalink
build: set noUncheckedIndexedAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcur committed Jul 11, 2023
1 parent 8896f58 commit 745eddb
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export default function Peripherals({ kit, configuration }: Props) {
{configuration.neverUsed && (
<AddPeripheral kit={kit} configuration={configuration} />
)}
{Object.keys(configuration.peripherals).map((peripheralId) => {
const peripheral = configuration.peripherals[peripheralId];
{Object.values(configuration.peripherals).map((peripheral) => {
return (
<ViewEditPeripheral
key={peripheral.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function EditOutput(props: PInner) {
: ["scheduled"];

let initialOutputType = possibleOutputTypes[0];
if (initialOutputType === undefined) {
throw new Error("Expected at least one output type.");
}

try {
initialOutputType = outputSettings.type;
} catch (_e) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function parseConfiguration(
interpolated,
setpoints,
} = settings as any;
fuzzyControl.input[peripheralName][quantityTypeId] = {
fuzzyControl.input[peripheralName]![quantityTypeId]! = {
nominalRange,
nominalDeltaRange,
deltaMeasurements,
Expand All @@ -107,7 +107,7 @@ function parseConfiguration(
commandSettings as any
)) {
const { type, continuous, scheduled } = settings as any;
fuzzyControl.output[peripheralName][command] = {
fuzzyControl.output[peripheralName]![command]! = {
type,
continuous,
scheduled,
Expand Down Expand Up @@ -137,7 +137,7 @@ function parseConfiguration(
continue;
}

if (!(quantityType in fuzzyControl.input[peripheral])) {
if (!(quantityType in fuzzyControl.input[peripheral]!)) {
continue;
}

Expand All @@ -158,7 +158,7 @@ function parseConfiguration(
continue;
}

if (!(command in fuzzyControl.output[peripheral])) {
if (!(command in fuzzyControl.output[peripheral]!)) {
continue;
}

Expand All @@ -176,7 +176,7 @@ function parseConfiguration(
continue;
}

if (!(command in fuzzyControl.output[peripheral])) {
if (!(command in fuzzyControl.output[peripheral]!)) {
continue;
}

Expand Down Expand Up @@ -259,7 +259,7 @@ class Rules extends React.Component<Props, State> {
if (!(peripheral.name in draft.input)) {
draft.input[peripheral.name] = {};
}
draft.input[peripheral.name][quantityType.id] = {
draft.input[peripheral.name]![quantityType.id] = {
nominalRange: 1.0,
nominalDeltaRange: 0.1,
deltaMeasurements: 1,
Expand All @@ -284,15 +284,15 @@ class Rules extends React.Component<Props, State> {
draft.output[peripheral.name] = {};
}
if (schema.type && schema.type === "number") {
draft.output[peripheral.name][command] = {
draft.output[peripheral.name]![command] = {
type: "continuous",
continuous: {
minimal: (schema as any).minimal || 0.0,
maximal: (schema as any).maximal || 100.0,
},
};
} else {
draft.output[peripheral.name][command] = {
draft.output[peripheral.name]![command] = {
type: "scheduled",
// @ts-ignore
scheduled: {
Expand Down Expand Up @@ -348,7 +348,7 @@ class Rules extends React.Component<Props, State> {
});

const fuzzyControl = produce(this.state.fuzzyControl, (draft) => {
draft.input[peripheral.name][quantityType.id] = inputSettingsSorted;
draft.input[peripheral.name]![quantityType.id] = inputSettingsSorted;
});

this.update(fuzzyControl);
Expand All @@ -360,7 +360,7 @@ class Rules extends React.Component<Props, State> {
outputSettings: OutputSettings
) => {
const fuzzyControl = produce(this.state.fuzzyControl, (draft) => {
draft.output[peripheral.name][command] = outputSettings;
draft.output[peripheral.name]![command] = outputSettings;
});

this.update(fuzzyControl);
Expand All @@ -376,8 +376,8 @@ class Rules extends React.Component<Props, State> {

deleteInput = (peripheral: Peripheral, quantityType: QuantityType) => {
const fuzzyControl = produce(this.state.fuzzyControl, (draft) => {
delete draft.input[peripheral.name][quantityType.id];
if (Object.values(draft.input[peripheral.name]).length === 0) {
delete draft.input[peripheral.name]![quantityType.id];
if (Object.values(draft.input[peripheral.name]!).length === 0) {
delete draft.input[peripheral.name];
}
});
Expand All @@ -387,8 +387,8 @@ class Rules extends React.Component<Props, State> {

deleteOutput = (peripheral: Peripheral, command: string) => {
const fuzzyControl = produce(this.state.fuzzyControl, (draft) => {
delete draft.output[peripheral.name][command];
if (Object.values(draft.output[peripheral.name]).length === 0) {
delete draft.output[peripheral.name]![command];
if (Object.values(draft.output[peripheral.name]!).length === 0) {
delete draft.output[peripheral.name];
}
});
Expand Down Expand Up @@ -421,7 +421,7 @@ class Rules extends React.Component<Props, State> {
for (const quantityType of peripheralDefinition.expectedQuantityTypes!) {
if (
!(peripheral.name in fuzzyControl.input) ||
!(quantityType in fuzzyControl.input[peripheral.name])
!(quantityType in fuzzyControl.input[peripheral.name]!)
) {
undefinedPeripheralQuantityTypes.push([
peripheral,
Expand All @@ -448,7 +448,7 @@ class Rules extends React.Component<Props, State> {
for (const [key, val] of Object.entries(schema.properties) as any) {
if (
!(peripheral.name in fuzzyControl.output) ||
!(key in fuzzyControl.output[peripheral.name])
!(key in fuzzyControl.output[peripheral.name]!)
) {
undefinedPeripheralCommands.push([peripheral, key, val]);
}
Expand Down Expand Up @@ -491,7 +491,7 @@ class Rules extends React.Component<Props, State> {
{Object.entries(qtInput).map(([quantityTypeId, settings]) => {
const peripheral = Object.values(
configuration.peripherals
).filter((p) => p.name === peripheralName)[0];
).filter((p) => p.name === peripheralName)[0]!;
const quantityType = quantityTypes[quantityTypeId]!;
return (
<div key={quantityTypeId}>
Expand Down Expand Up @@ -569,7 +569,7 @@ class Rules extends React.Component<Props, State> {
{Object.entries(commandOutput).map(([command, settings]) => {
const peripheral = Object.values(
configuration.peripherals
).filter((p) => p.name === peripheralName)[0];
).filter((p) => p.name === peripheralName)[0]!;
const peripheralDefinition =
peripheralDefinitions[peripheral.peripheralDefinitionId]!;
const schema = (peripheralDefinition.commandSchema as any)
Expand Down Expand Up @@ -672,7 +672,7 @@ class Rules extends React.Component<Props, State> {

{this.state.editingRule
.map((index) => {
const rule = fuzzyControl.rules[index];
const rule = fuzzyControl.rules[index]!;
let conditionChoices: [string, QuantityType][] = [];
let implicationChoices: [string, string][] = [];
let scheduleChoices: [string, string][] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default function AggregateMeasurementsChart(props: Props) {
}

let minGap = Infinity;
let prevDatetime = measurements[0].datetimeStart;
let prevDatetime = measurements[0]!.datetimeStart;
for (const measurement of measurements.slice(1)) {
const gap = measurement.datetimeStart.getTime() - prevDatetime.getTime();
prevDatetime = measurement.datetimeStart;
Expand All @@ -138,7 +138,7 @@ export default function AggregateMeasurementsChart(props: Props) {
}

let startIdx = 0;
prevDatetime = measurements[0].datetimeStart;
prevDatetime = measurements[0]!.datetimeStart;
// @ts-ignore
for (const [idx, measurement] of measurements.slice(1).entries()) {
const gap = measurement.datetimeStart.getTime() - prevDatetime.getTime();
Expand Down
2 changes: 1 addition & 1 deletion astroplant-frontend/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function walkPages<T extends { id: number }>(
if (result.length === 0) {
return EMPTY;
} else {
return request(result[result.length - 1].id).pipe(requestWrapper());
return request(result[result.length - 1]!.id).pipe(requestWrapper());
}
}
});
Expand Down
1 change: 1 addition & 0 deletions astroplant-frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
Expand Down

0 comments on commit 745eddb

Please sign in to comment.