Skip to content

How can I add collection types to my code? #310

Answered by ollema
benquan asked this question in Q&A
Discussion options

You must be logged in to vote

I'm pretty sure you should define this type yourself, in for example src/lib/types.ts:

export type Todo = {
    id: string;
    text: string;
    created: string;
    updated: string;
};

Also, I don't think you should query pocketbase from the page component, instead you should probably use a page endpoint.

You would end up with the page endpoint index.ts:

import type { RequestHandler } from '@sveltejs/kit';
import type { Todo } from '$lib/types';

import PocketBase from 'pocketbase';
const client = new PocketBase('http://127.0.0.1:8090');

export const GET: RequestHandler = async () => {
    const result = await client.records.getList('todo', 1, 20);
    const todos: Todo[] = result.items.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ollema
Comment options

Answer selected by benquan
Comment options

You must be logged in to vote
1 reply
@ganigeorgiev
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants