Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[types] Expand should ignore builtins #654

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions client/packages/core/src/queryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import type {
ResolveEntityAttrs,
} from "./schemaTypes";

type Expand<T> = T extends object
? T extends infer O
? { [K in keyof O]: Expand<O[K]> }
: never
: T;
type BuiltIn = Date | Function | Error | RegExp;

type Expand<T> = T extends BuiltIn
? T
: T extends object
? T extends infer O
? { [K in keyof O]: Expand<O[K]> }
: never
: T;

// NonEmpty disallows {}, so that you must provide at least one field
type NonEmpty<T> = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { init, BackwardsCompatibleSchema } from "@instantdb/react";

type Message = {
content: string;
createdAt: Date;
};

type User = {
email: string;
};

type Schema = {
messages: Message;
creator: User;
};

type EmojiName = "fire" | "wave" | "confetti" | "heart";

type Rooms = {
chat: {
presence: {
name: string;
avatarURI: string;
};
topics: {
emoji: {
name: EmojiName;
rotationAngle: number;
directionAngle: number;
};
};
};
};

// ----
// Core

const db = init<BackwardsCompatibleSchema<Schema, Rooms>>({
appId: import.meta.env.VITE_INSTANT_APP_ID,
});

const res = db.useQuery({ messages: { creator: {} }})
const m = res.data?.messages[0];
// Hover over `m` to see that `m?.createdAt` and see that it says `Date`;
m?.createdAt;



Loading