This is a draft where we can think of how to improve the FaunaDB JS driver type system, so if you have any suggestions on how we can improve this, feel free to comment and submit your changes.
Current
import faunadb from "faunadb";
type Note = {
ref: faunadb.values.Ref;
ts: number;
data: {
content: string;
};
};
Proposal
import faunadb, { Ref } from "faunadb";
type Note = {
ref: Ref;
ts: number;
data: {
content: string;
};
};
Current
import faunadb from "faunadb";
type Note = {
ref: faunadb.values.Ref;
ts: number;
data: {
content: string;
};
};
Proposal
import faunadb, { Document } from "faunadb"
type Note = Document<{
data: {
content: string
}
}>
Current
// The return type of query() is 'object'
import faunadb, { query as q } from "faunadb";
const result = client.query(q.Get(q.Ref(...)));
console.log(result.ref.id) // Throws an error: Property 'ref' does not exist on type 'object'
Proposal
import faunadb, { query as q, Document } from "faunadb";
type Note = Document<{
data: {
content: string
}
}>
const note: Note = client.query<Note>(q.Get(q.Ref(...)));
console.log(note.ref.id) // Works good!
Current
# query() returns {} or any
import faunadb, { query as q } from "faunadb";
const result: {} = client.query(q.Paginate(q.Match(...)));
Proposal
import faunadb, { query as q, Document, Page } from "faunadb";
type Note = Document<{
data: {
content: string
}
}>
const notes = client.query<Page<Note>>(q.Paginate(q.Match(...)));
Really looking forward to this! Especially the client.query getting a real type.