Skip to content

Commit

Permalink
[types] Expand should ignore builtins (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
stopachka authored Dec 23, 2024
1 parent 3d391f4 commit 84a3975
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
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;



0 comments on commit 84a3975

Please sign in to comment.