feat: enable stricter type checking options

feat: make the app more fault tolerant
This commit is contained in:
2024-04-06 14:28:23 +02:00
parent bef51d2a7d
commit 2808973ad0
38 changed files with 152 additions and 121 deletions

View File

@@ -95,6 +95,7 @@ export function restoreFromFile(
switch (file.type) {
case "backup": {
const recent = file.history[0];
if (!recent) return;
if (recent[1].device !== get(serialPort)?.device) {
alert("Backup is incompatible with this device");
throw new Error("Backup is incompatible with this device");
@@ -177,7 +178,7 @@ export function getChangesFromLayoutFile(file: CharaLayoutFile) {
const changes: Change[] = [];
for (const [layer, keys] of file.layout.entries()) {
for (const [id, action] of keys.entries()) {
if (get(layout)[layer][id].action !== action) {
if (get(layout)[layer]?.[id]?.action !== action) {
changes.push({
type: ChangeType.Layout,
layer,

View File

@@ -13,11 +13,11 @@ export function csvChordsToJson(csv: string): CharaChordFile {
.map((line) => {
const [input, output] = line.split(/,(?=[^,]*$)/, 2);
return [
input
input!
.split("+")
.map((it) => KEYMAP_IDS.get(it.trim())?.code ?? 0)
.sort((a, b) => a - b),
output
output!
.trim()
.split("")
.map((it) => KEYMAP_IDS.get(SPECIAL_KEYS.get(it) ?? it)?.code ?? 0),

View File

@@ -17,7 +17,7 @@ export function csvLayoutToJson(
for (const layer of csv.trim().split("\n")) {
const [layerId, key, action] = layer.substring(1).split(",").map(Number);
layout.layout[Number(layerId) - 1][Number(key)] = Number(action);
layout.layout[Number(layerId) - 1]![Number(key)] = Number(action);
}
return layout;