diff --git a/client/sandbox/strong-init-vite/src/typescript_test_abstract.tsx b/client/sandbox/strong-init-vite/src/typescript_test_abstract.tsx index 81d569f9..5de0ecbd 100644 --- a/client/sandbox/strong-init-vite/src/typescript_test_abstract.tsx +++ b/client/sandbox/strong-init-vite/src/typescript_test_abstract.tsx @@ -11,7 +11,7 @@ const db = init({ schema, }); -type Collection = keyof typeof schema.entities; +type Collection = keyof AppSchema['entities']; type EntityUpdate = UpdateParams; diff --git a/client/www/pages/docs/instaml.md b/client/www/pages/docs/instaml.md index 15638cc7..cad31834 100644 --- a/client/www/pages/docs/instaml.md +++ b/client/www/pages/docs/instaml.md @@ -285,12 +285,52 @@ const _schema = i.schema({ }, // ... }); +// ... ``` -Instant will enforce that `todos.dueDate` are actually dates, and you'll get intellisense to boot: +Instant will enforce that `todos.dueDate` are actually dates, and you'll get some nice intellisense to boot: {% screenshot src="/img/docs/instaml-due-date.png" /%} +Instant also comes with a few utility types, which can help you write abstractions over `transact`. For example, say you wanted to write a custom `update` function: + +```typescript +// Goal +myCustomUpdate('todos', { dueDate: Date.now() } ); +``` + +You can use the `UpdateParams` utility to make sure arguments follow the schema: + +```typescript +import { UpdateParams } from '@instantdb/react'; +import { AppSchema } from '../instant.schema.ts'; + +type EntityTypes = keyof AppSchema['entities']; + +function myCustomUpdate( + etype: EType, + args: UpdateParams, +) { + // .. +} +``` + +And the `LinkParams` utility do the same for links: + +```typescript +import { UpdateParams } from '@instantdb/react'; +import { AppSchema } from '../instant.schema.ts'; + +type EntityTypes = keyof AppSchema['entities']; + +function myCustomLink( + etype: EType, + args: LinkParams, +) { + // .. +} +``` + To learn more about writing schemas, check out the [Modeling Data](/docs/modeling-data) section. ## Batching transactions