Skip to content

Commit 2e18f42

Browse files
committed
fix type errors
1 parent a349689 commit 2e18f42

File tree

6 files changed

+54
-47
lines changed

6 files changed

+54
-47
lines changed

src/lib/types/index.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@ export interface Warning {
8989
frame: string;
9090
message: string;
9191
}
92+
93+
export interface MenuItem {
94+
icon: string;
95+
label: string;
96+
fn: () => void;
97+
}

src/routes/tutorial/[slug]/filetree/ContextMenu.svelte

+2-6
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,14 @@
55
import { writable } from 'svelte/store';
66
77
/**
8-
* @typedef {{ icon: string; label: string; fn: () => void }} MenuItem
9-
*/
10-
11-
/**
12-
* @type {import("svelte/store").Writable<{x: number; y: number; items: MenuItem[]} | null>}
8+
* @type {import("svelte/store").Writable<{x: number; y: number; items: import('$lib/types').MenuItem[]} | null>}
139
*/
1410
let menu_items = writable(null);
1511
1612
/**
1713
* @param {number} x
1814
* @param {number} y
19-
* @param {MenuItem[]} items
15+
* @param {import('$lib/types').MenuItem[]} items
2016
*/
2117
export function open(x, y, items) {
2218
if (items.length > 0) {

src/routes/tutorial/[slug]/filetree/File.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
1717
$: can_remove = !$solution[file.name];
1818
19-
/** @type {import('./ContextMenu.svelte').MenuItems} */
19+
/** @type {import('$lib/types').MenuItem[]} */
2020
$: actions = can_remove
2121
? [
2222
{

src/routes/tutorial/[slug]/filetree/Filetree.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@
146146
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
147147
e.preventDefault();
148148
const lis = Array.from(e.currentTarget.querySelectorAll('li'));
149-
const focused = lis.findIndex((li) => li.contains(e.target));
149+
const focused = lis.findIndex((li) => li.contains(/** @type {HTMLElement} */ (e.target)));
150150

151151
const d = e.key === 'ArrowUp' ? -1 : +1;
152152

src/routes/tutorial/[slug]/filetree/Folder.svelte

+43-38
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@
3333
(child) => get_depth(child.name) === segments && child.type === 'directory'
3434
);
3535
36-
$: child_files = /** @type {import('$lib/types').FileStub[]} */ (
37-
children.filter((child) => get_depth(child.name) === segments && child.type === 'file')
36+
// prettier-ignore
37+
$: child_files = (
38+
/** @type {import('$lib/types').FileStub[]} */ (
39+
children.filter((child) => get_depth(child.name) === segments && child.type === 'file')
40+
)
3841
);
3942
4043
const can_create = { file: false, directory: false };
@@ -71,43 +74,45 @@
7174
// fake root directory has no name
7275
$: can_remove = directory.name ? !$solution[directory.name] : false;
7376
74-
/** @type {import('./ContextMenu.svelte').MenuItem[]} */
75-
$: actions = [
76-
can_create.file && {
77-
icon: 'file-new',
78-
label: 'New file',
79-
fn: () => {
80-
creating.set({
81-
parent: directory.name,
82-
type: 'file'
83-
});
77+
// prettier-ignore
78+
$: actions = (
79+
/** @type {import('$lib/types').MenuItem[]} */ ([
80+
can_create.file && {
81+
icon: 'file-new',
82+
label: 'New file',
83+
fn: () => {
84+
creating.set({
85+
parent: directory.name,
86+
type: 'file'
87+
});
88+
}
89+
},
90+
can_create.directory && {
91+
icon: 'folder-new',
92+
label: 'New folder',
93+
fn: () => {
94+
creating.set({
95+
parent: directory.name,
96+
type: 'directory'
97+
});
98+
}
99+
},
100+
can_remove && {
101+
icon: 'rename',
102+
label: 'Rename',
103+
fn: () => {
104+
renaming = true;
105+
}
106+
},
107+
can_remove && {
108+
icon: 'delete',
109+
label: 'Delete',
110+
fn: () => {
111+
remove(directory);
112+
}
84113
}
85-
},
86-
can_create.directory && {
87-
icon: 'folder-new',
88-
label: 'New folder',
89-
fn: () => {
90-
creating.set({
91-
parent: directory.name,
92-
type: 'directory'
93-
});
94-
}
95-
},
96-
can_remove && {
97-
icon: 'rename',
98-
label: 'Rename',
99-
fn: () => {
100-
renaming = true;
101-
}
102-
},
103-
can_remove && {
104-
icon: 'delete',
105-
label: 'Delete',
106-
fn: () => {
107-
remove(directory);
108-
}
109-
}
110-
].filter(Boolean);
114+
].filter(Boolean))
115+
);
111116
</script>
112117

113118
<Item

src/routes/tutorial/[slug]/filetree/Item.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/** @type {boolean} */
1515
export let renaming;
1616
17-
/** @type {import('./ContextMenu.svelte').MenuItem[]} */
17+
/** @type {import('$lib/types').MenuItem[]} */
1818
export let actions = [];
1919
2020
const dispatch = createEventDispatcher();

0 commit comments

Comments
 (0)