fix: resolve all 15 svelte-check type errors
- Type headers as Record<string, string> in apiRequest (client.js)
- Annotate SyncResult on result object, cast catch vars to any (sync.js)
- Widen sync.push param to Partial<Task>[] (endpoints.js)
- Fix parse() return type to reflect {task?: Task} shape (endpoints.js)
- Narrow add() param from Partial<Task> to Task (tasks.js)
- Cast parseAndCreate result to Task (tasks.js)
- Type tasksByProject grouped object as Record<string, Task[]> (tasks.js)
svelte-check now reports 0 errors and 0 warnings.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,9 +18,10 @@ export const API_BASE = import.meta.env.VITE_API_URL || 'http://localhost:8080';
|
||||
export async function apiRequest(endpoint, options = {}) {
|
||||
const auth = get(authStore);
|
||||
|
||||
/** @type {Record<string, string>} */
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
...options.headers
|
||||
.../** @type {Record<string, string>} */ (options.headers)
|
||||
};
|
||||
|
||||
if (auth.accessToken) {
|
||||
|
||||
@@ -76,7 +76,7 @@ export const tasks = {
|
||||
|
||||
/**
|
||||
* @param {string} input - Raw opal CLI syntax
|
||||
* @returns {Promise<Task>}
|
||||
* @returns {Promise<{task?: Task} & Task>}
|
||||
*/
|
||||
async parse(input) {
|
||||
return apiRequest('/tasks/parse', {
|
||||
@@ -143,7 +143,7 @@ export const sync = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Task[]} tasks
|
||||
* @param {Partial<Task>[]} tasks
|
||||
* @param {string} clientId
|
||||
* @returns {Promise<{processed: number, conflicts: number}>}
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,8 @@ function createSyncStore() {
|
||||
const state = loadSyncState();
|
||||
const queue = getQueue();
|
||||
|
||||
let result = {
|
||||
/** @type {SyncResult} */
|
||||
const result = {
|
||||
pulled: 0,
|
||||
pushed: 0,
|
||||
conflicts_resolved: 0,
|
||||
@@ -70,7 +71,7 @@ function createSyncStore() {
|
||||
await syncAPI.push(tasks, state.clientId);
|
||||
clearQueue();
|
||||
result.pushed = queue.length;
|
||||
} catch (error) {
|
||||
} catch (/** @type {any} */ error) {
|
||||
result.errors.push(`Failed to push queue: ${error.message}`);
|
||||
}
|
||||
}
|
||||
@@ -79,7 +80,7 @@ function createSyncStore() {
|
||||
const changes = await syncAPI.getChanges(state.lastSync, state.clientId);
|
||||
result.pulled = changes.length;
|
||||
// TODO: Apply changes to local state
|
||||
} catch (error) {
|
||||
} catch (/** @type {any} */ error) {
|
||||
result.errors.push(`Failed to pull changes: ${error.message}`);
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ function createSyncStore() {
|
||||
}));
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
} catch (/** @type {any} */ error) {
|
||||
update(state => ({
|
||||
...state,
|
||||
status: 'error',
|
||||
|
||||
@@ -42,7 +42,7 @@ function createTasksStore() {
|
||||
async parseAndCreate(input) {
|
||||
try {
|
||||
const result = await tasksAPI.parse(input);
|
||||
const created = result.task ?? result;
|
||||
const created = /** @type {Task} */ (result.task ?? result);
|
||||
update(tasks => [created, ...tasks]);
|
||||
return created;
|
||||
} catch (error) {
|
||||
@@ -64,7 +64,7 @@ function createTasksStore() {
|
||||
|
||||
/**
|
||||
* Optimistic create — queues offline on failure.
|
||||
* @param {Partial<Task>} task
|
||||
* @param {Task} task
|
||||
*/
|
||||
async add(task) {
|
||||
try {
|
||||
@@ -172,6 +172,7 @@ export const completedTasks = derived(
|
||||
export const tasksByProject = derived(
|
||||
tasksStore,
|
||||
$tasks => {
|
||||
/** @type {Record<string, Task[]>} */
|
||||
const grouped = {};
|
||||
$tasks.forEach(task => {
|
||||
const project = task.project || 'No Project';
|
||||
|
||||
Reference in New Issue
Block a user