-
-
Notifications
You must be signed in to change notification settings - Fork 553
fix(types): switch order of schema type arguments - @macinjoke #875
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #875 +/- ##
=======================================
Coverage 88.77% 88.77%
=======================================
Files 29 29
Lines 784 784
=======================================
Hits 696 696
Misses 88 88 |
|
Switching these arguments was in attempt to get the schema feature added in this PR to work as expected. Is there a reason for going back? I understand that it became breaking for this switch, but seems like the right move since it was the original intention. What are your thoughts? |
|
Sorry, it was an inadequate change. The reason for ordering the |
|
It seems like the the ProfileType is set to an object already, so we should be able to remove the default setting there right? |
It seems that the ProfileType set here has nothing to do with the ProfileType of FirebaseReducer.Reducer. I think the type argument ProfileType is necessary for the user to specify a type like |
* feat(auth): add support for microsoft auth provider - @lucasharada (#880) * fix(types): switch order of schema type arguments - @macinjoke (#875) * feat(docs): update docs include microsoft.com provider - @lucasharada (#880) * feat(tests): add test for microsoft.com auth provider - @lucasharada (#880) * chore(ci): switch to Github Actions for CI in place of TravisCI * chore(build): add lint-staged for quicker lint checking on pre-commit * chore(deps): update dev dependencies including babel deps Co-authored-by: Lucas Harada <[email protected]> Co-authored-by: macinjoke <[email protected]>
|
Thanks for the PR. Released in v3.2.0 |
|
Guys! Stop changing the order! This is going to break our code again! @prescottprue I wish you would have asked me about this. Just give both types defaults like this: export function firebaseReducer<
UserType,
Schema extends Record<string, Record<string | number, string | number>>
>(state: any, action: any): FirebaseReducer.Reducer<UserType, Schema>
export function makeFirebaseReducer<
UserType = {},
Schema extends Record<string, Record<string | number, string | number>> = {}
>(): (state: any, action: any) => FirebaseReducer.Reducer<UserType, Schema>export namespace FirebaseReducer {
export interface Reducer<
ProfileType = {},
Schema extends Record<string, Record<string | number, string | number>> = {}
> {This way nobody needs to add the And Please make the changes I gave above or let me know and I'll submit a PR to make the change. |
|
@prescottprue @macinjoke I submitted PR #888 with the preferred approach to solving this type error. |
|
@macinjoke You could have solved this problem without creating a PR with breaking changes simply by doing this: FirebaseReducer.Reducer<{}, {}> |
|
Thanks for the PR @rscotten! For some reason I thought that is what the last PR is doing, which is why I included it in 3.2.0. I'll get this out right away |
|
@prescottprue Thank you! :) |
Sounds great! Thank you. |
|
Would someone here be kind enough to share an example of how to use the Schema part of Trying to do something simple like: interface IContact {
name: string;
email: string;
}
// create schema for the DB
interface DBSchema {
contacts: IContact
}
export interface RootState {
firebase: FirebaseReducer.Reducer<IProfile, DBSchema>; // <--- Error here
firestore: FirestoreReducer.Reducer;
localSettings: ILocalSettings
loading: ILoading
}
const appReducer = combineReducers<RootState>({
localSettings: settingsReducer,
loading: loadingReducer,
firebase: firebaseReducer,
firestore: firestoreReducer,
}); |
|
@JonnyBoy333 The original PR was #826 which broke the codebase due to putting the new This is actually a known issue. The author of this change references it here: |
|
@JonnyBoy333 you can hack it by doing either: combineReducers<RootState>({
// @ts-ignore <-- you can add this
firebase: firebaseReducer as any, // <-- or this
}); |
|
@JonnyBoy333 figured it out. The type definitions need to be changed in export function firebaseReducer<
UserType extends Record<string, any> = {},
Schema extends Record<string, any> = {}
>(state: any, action: any): FirebaseReducer.Reducer<UserType, Schema>
export function makeFirebaseReducer<
UserType extends Record<string, any> = {},
Schema extends Record<string, any> = {}
>(): (state: any, action: any) => FirebaseReducer.Reducer<UserType, Schema> |
|
@JonnyBoy333 @prescottprue submitted PR #906 to fix this. |
|
@rscotten Wow that was quick, thank you and also thanks for updating the documentation. I tried copying your updated index.d.ts into my project and I am still getting an error (even with your documentation example). It's the same error as before and I think it's because there is another reducer type on line 1134. Here: react-redux-firebase/index.d.ts Line 1134 in cfc516c
This is what gets referenced when you call |
|
@JonnyBoy333 Good catch. Fixed. Thanks! |
|
@rscotten Confirmed, no more errors here. I hope someday someone will do the same for Firestore schemas 🤞. |
Description
fixed this.
https://github.com/prescottprue/react-redux-firebase/pull/826/files#r386035738
Check List
If not relevant to pull request, check off as complete
Relevant Issues