Skip to content

Commit

Permalink
chore: fix type errors (#624)
Browse files Browse the repository at this point in the history
* bump svelte-check version

* fix type errors
  • Loading branch information
Rich-Harris authored May 27, 2024
1 parent e7b0c88 commit a345dca
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 53 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"prettier-plugin-svelte": "^3.0.3",
"shiki-twoslash": "^3.1.2",
"svelte": "^4.2.0",
"svelte-check": "^3.5.1",
"svelte-check": "^3.7.1",
"tiny-glob": "^0.2.9",
"typescript": "^5.3.3",
"vite": "^5.0.0"
Expand Down
11 changes: 6 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/lib/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ export interface Warning {
frame: string;
message: string;
}

export interface MenuItem {
icon: string;
label: string;
fn: () => void;
}
8 changes: 2 additions & 6 deletions src/routes/tutorial/[slug]/filetree/ContextMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
import { writable } from 'svelte/store';
/**
* @typedef {{ icon: string; label: string; fn: () => void }} MenuItem
*/
/**
* @type {import("svelte/store").Writable<{x: number; y: number; items: MenuItem[]} | null>}
* @type {import("svelte/store").Writable<{x: number; y: number; items: import('$lib/types').MenuItem[]} | null>}
*/
let menu_items = writable(null);
/**
* @param {number} x
* @param {number} y
* @param {MenuItem[]} items
* @param {import('$lib/types').MenuItem[]} items
*/
export function open(x, y, items) {
if (items.length > 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/tutorial/[slug]/filetree/File.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$: can_remove = !$solution[file.name];
/** @type {import('./ContextMenu.svelte').MenuItems} */
/** @type {import('$lib/types').MenuItem[]} */
$: actions = can_remove
? [
{
Expand Down
2 changes: 1 addition & 1 deletion src/routes/tutorial/[slug]/filetree/Filetree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
e.preventDefault();
const lis = Array.from(e.currentTarget.querySelectorAll('li'));
const focused = lis.findIndex((li) => li.contains(e.target));
const focused = lis.findIndex((li) => li.contains(/** @type {HTMLElement} */ (e.target)));

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

Expand Down
81 changes: 43 additions & 38 deletions src/routes/tutorial/[slug]/filetree/Folder.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@
(child) => get_depth(child.name) === segments && child.type === 'directory'
);
$: child_files = /** @type {import('$lib/types').FileStub[]} */ (
children.filter((child) => get_depth(child.name) === segments && child.type === 'file')
// prettier-ignore
$: child_files = (
/** @type {import('$lib/types').FileStub[]} */ (
children.filter((child) => get_depth(child.name) === segments && child.type === 'file')
)
);
const can_create = { file: false, directory: false };
Expand Down Expand Up @@ -71,43 +74,45 @@
// fake root directory has no name
$: can_remove = directory.name ? !$solution[directory.name] : false;
/** @type {import('./ContextMenu.svelte').MenuItem[]} */
$: actions = [
can_create.file && {
icon: 'file-new',
label: 'New file',
fn: () => {
creating.set({
parent: directory.name,
type: 'file'
});
// prettier-ignore
$: actions = (
/** @type {import('$lib/types').MenuItem[]} */ ([
can_create.file && {
icon: 'file-new',
label: 'New file',
fn: () => {
creating.set({
parent: directory.name,
type: 'file'
});
}
},
can_create.directory && {
icon: 'folder-new',
label: 'New folder',
fn: () => {
creating.set({
parent: directory.name,
type: 'directory'
});
}
},
can_remove && {
icon: 'rename',
label: 'Rename',
fn: () => {
renaming = true;
}
},
can_remove && {
icon: 'delete',
label: 'Delete',
fn: () => {
remove(directory);
}
}
},
can_create.directory && {
icon: 'folder-new',
label: 'New folder',
fn: () => {
creating.set({
parent: directory.name,
type: 'directory'
});
}
},
can_remove && {
icon: 'rename',
label: 'Rename',
fn: () => {
renaming = true;
}
},
can_remove && {
icon: 'delete',
label: 'Delete',
fn: () => {
remove(directory);
}
}
].filter(Boolean);
].filter(Boolean))
);
</script>

<Item
Expand Down
2 changes: 1 addition & 1 deletion src/routes/tutorial/[slug]/filetree/Item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/** @type {boolean} */
export let renaming;
/** @type {import('./ContextMenu.svelte').MenuItem[]} */
/** @type {import('$lib/types').MenuItem[]} */
export let actions = [];
const dispatch = createEventDispatcher();
Expand Down

0 comments on commit a345dca

Please sign in to comment.