diff --git a/client/packages/core/src/queryTypes.ts b/client/packages/core/src/queryTypes.ts index b4fc60bb5..7a855e591 100644 --- a/client/packages/core/src/queryTypes.ts +++ b/client/packages/core/src/queryTypes.ts @@ -10,11 +10,15 @@ import type { ResolveEntityAttrs, } from "./schemaTypes"; -type Expand = T extends object - ? T extends infer O - ? { [K in keyof O]: Expand } - : never - : T; +type BuiltIn = Date | Function | Error | RegExp; + +type Expand = T extends BuiltIn + ? T + : T extends object + ? T extends infer O + ? { [K in keyof O]: Expand } + : never + : T; // NonEmpty disallows {}, so that you must provide at least one field type NonEmpty = { diff --git a/client/sandbox/strong-init-vite/src/typescript_tests_backwards_compat_date.tsx b/client/sandbox/strong-init-vite/src/typescript_tests_backwards_compat_date.tsx new file mode 100644 index 000000000..8696d859f --- /dev/null +++ b/client/sandbox/strong-init-vite/src/typescript_tests_backwards_compat_date.tsx @@ -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>({ + 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; + + +