-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Type '(payload: Partial<Pokemon>) => Pokemon' is not assignable to type 'OnAddedFn' #76
Comments
@vdsbenoit thanks for finding this! So I have typed the /**
* Can be used to modify docs that come in from 'stream' or 'fetch' actions, before they are added to your store data. When returning `undefined` they will be discarded & won't be added to the store data.
*/
export type OnAddedFn = (docData: Record<string, any> | undefined, docMetadata: DocMetadata) => Record<string, any> | void see source code at: But I don't think we should ever execute the Changing my underlying type to this will fix the issue: /**
* Can be used to modify docs that come in from 'stream' or 'fetch' actions, before they are added to your store data. When returning `undefined` they will be discarded & won't be added to the store data.
*/
export type OnAddedFn = (docData: Record<string, any>, docMetadata: DocMetadata) => Record<string, any> | void So I will do this somewhere this week after checking this won't cause issues. In the meanwhile you can fix the issue on your end with a workaround of adding a simple export function pokemonDefaults(payload?: Partial<Pokemon>): Pokemon {
const defaults: Pokemon = { name: '', nickName: '', id: '', level: 0 }
return { ...defaults, ...payload }
} see the |
Thanks a lot for your quick reply ! I'll try that |
@vdsbenoit you can now define the type of your document when inserting separately from the type of your module doc. const pokedexModule = magnetar.collection<Pokemon, { insert: Partial<Pokemon> }>('pokedex',
modifyPayloadOn: { insert: pokemonDefaults },
modifyReadResponseOn: { added: pokemonDefaults },
}) this will make it so executing Does this help you further? |
@vdsbenoit on This means that there is no possibility that the payload of This means that the documentation example is now possible without type issues. workaround: let me know if you have any further issues. |
Hi @mesqueeb, Thanks a lot for the support! Unfortunately, I am no longer working on this personal project for the moment. But I will hopefully get back to it in a couple of months. While I am confident you have fixed my problem, I will get back to you if I still face any issues. Cheers, Benoit |
Hi, I'm diving into my side project again (it's for an event that takes place once a year). I upgraded magnetar from 0.5.4 to 0.11.4. I confirm the issue is resolved! Thanks again for your support ! |
Hi @mesqueeb,
First of all, thanks a lot for the great work you have done here ! It is much appreciated πββοΈ
I am trying to configure magnetar in a project I recently started with Vue 3. However, I am having trouble to make it work with TypeScript. To simplify my description, I am going to use the example provided in your documentation.
When I try to transpile this snippet :
I get this error:
Do you have an idea what could have gone wrong?
Here is my config
The text was updated successfully, but these errors were encountered: