Better TypeScript Support #33
Replies: 7 comments 10 replies
-
Hey @SuperSonicHub1! You should take a look at the v2.2 release (currently in beta, but set to roll today). It's not quite the generic-based implementation you suggest, but it can can (either programmatically or on the command line) take the schema and generate a typed wrapper with domain-specific methods etc. Take a look at https://beta.tinybase.org/guides/developer-tools/generating-apis/ and https://beta.tinybase.org/guides/developer-tools/command-line/ and let me know what you think. (In a couple of hours, these URLs will also work without the beta subdomain ;) ) |
Beta Was this translation helpful? Give feedback.
-
Great! I guess next steps for me are to take my TypeScript schemas and convert them to TinyBase ones. Thanks for working on TinyBase; it's been a lot of fun writing a offline-first Mastodon client that implements the relational philosopy of Riffle using it! I should have a 0.1.0 of the app done in the coming weeks; I'll make sure to share it here as I think it might be helpful for you guys seeing as I'm likely one of the first devs to write a full app with TinyBase (if you do know of any others, please let me know!). |
Beta Was this translation helpful? Give feedback.
-
Another idea for better TypeScript support: infer types for tables, rows, and cells from a schema and use those to strongly type all the functions of the library, directly in TypeScript. I'm thinking of something in the style of Example: const store = createStore().setSchema({
pets: {
species: { type: "string" },
sold: { type: "boolean" },
},
});
// Should be a type error
store.getTable("pet");
// Should have type: `Record<string, { species: string; sold: boolean; }>`
const table = store.getTable("pets");
// Should have type `{ species: string; sold: boolean; }`
const row = table["felix"]; It has the advantage of not requiring any code generation. I suspect this approach could also accept a generic argument to If this is of interest, I'd be happy to work on it, I've implemented similar TypeScript tricks in the past. We're planning on using TinyBase in our app for offline support and cross-tab sync & this feature would be very helfpul. |
Beta Was this translation helpful? Give feedback.
-
Hey @erwinkn! Just checking in to see how this is going :) Also wanted to make sure you were keeping an eye on the |
Beta Was this translation helpful? Give feedback.
-
Hey @erwinkn! Just checking in to see how this is going :) Also wanted to make sure you were keeping an eye on the |
Beta Was this translation helpful? Give feedback.
-
Keep an eye on #50, the beta branch, and https://twitter.com/jamespearce/status/1631406755082117121 - this will be coming in v3.1, not too differently to what was asked for here! |
Beta Was this translation helpful? Give feedback.
-
Please kick the tires on https://github.com/tinyplex/tinybase/releases/tag/v3.1.0-beta.3 (So far I couldn't do this without some thin code generation ('refinement') because the schema can be replaced and removed at runtime. I suspect that to fulfill the dream I'll need a core Store API change, so maybe a v4.0 sort of thing.) |
Beta Was this translation helpful? Give feedback.
-
I'm using TinyBase in a TypeScript web app and would like to be able to statically enforce my schema instead of using TypeScript instead of at runtime using
Table.setSchema
. I think it could work something like this:This will allow me to reuse existing types with TinyBase and not have TypeScript be mad at me. :)
If this is already possible, please let me know.
Beta Was this translation helpful? Give feedback.
All reactions