-
-
Notifications
You must be signed in to change notification settings - Fork 553
feat(types): add support for typed db schema #826
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 #826 +/- ##
=======================================
Coverage 91.43% 91.43%
=======================================
Files 29 29
Lines 759 759
=======================================
Hits 694 694
Misses 65 65 |
|
Amazing work! Thanks for the PR! I think this is part of what what was being described in #670 Since this doesn't seem to be breaking in anyway we should be able to get this out in a new minor version |
|
That's great 😄 I gave it a bit thought and here are things that we should consider (but note it's not necesarrily to be implemented now. I think these types should be rather released as soon as possible, feedback should be gathered and then they should be gradually improved):
{
todos: { ... },
counters: {
todos: 15
}
}it should be reflected in schema so it doesn't produce a import { Collection } from 'react-redux-firebase';
interface Counters {
todos: number;
}
interface Schema {
todos: Collection<Todo>;
counters: Counters;
}and then branching on it using most probably conditional types. {
users: {
1: { name: "John Doe" }
},
todos: {
1: { // user's 1 todos
2: {
description: "Some todo"
}
}
}
}(then retrieving todos for user 1 is simpler). How should it be handled? How is it currently handled by implementation itself? |
|
Guys, any conclusions on above? I'd love to have this feature in my project :) |
|
Love the idea you are mentioning above, but agree it can come at a later time. Going to point this to v3.1.0 and so that we can get it released - I'm thinking we will also want to add something about this to the documentation for other folks to get the same benefits. Is the |
|
@prescottprue Great. Unfortunately, combineReducers({
firebase: firebaseReducer<DBSchema> // <-- won't compile
})Also, I don't really have free time to polish it nor write proper documentation, but in case of any questions regarding Typescript/anything else I'd be happy to help 👍 |
* fix(auth): remove stale profile listener on empty auth state change - @illuminist - #508, #838 * feat(types): add support for typed db schema - @vicrac - #826 * feat(auth): add reauthenticate method from firebase - @magrinj - #812 * chore(deps): bump lodash from 4.17.11 to 4.17.15 in react-native example - @dependabot * chore(deps): bump stringstream from 0.0.5 to 0.0.6 in react-native-firebase example - @dependabot * chore(deps): bump mixin-deep from 1.3.1 to 1.3.2 in react-native example - @dependabot * chore(deps): bump diff in react-native-firebase example - @dependabot * chore(deps): bump lodash-es from 4.17.4 to 4.17.15 in react-native-firebase example - @dependabot * chore(deps): bump diff from 3.3.0 to 3.5.0 in react-native-firebase example - @dependabot Co-authored-by: Jérémy M <[email protected]> Co-authored-by: Michał Kaczanowicz <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: illuminist <[email protected]>
* fix(auth): remove stale profile listener on empty auth state change - @illuminist - #508, #838 * feat(types): add support for typed db schema - @vicrac - #826 * feat(auth): add reauthenticate method from firebase - @magrinj - #812 * chore(deps): bump lodash from 4.17.11 to 4.17.15 in react-native example - @dependabot * chore(deps): bump stringstream from 0.0.5 to 0.0.6 in react-native-firebase example - @dependabot * chore(deps): bump mixin-deep from 1.3.1 to 1.3.2 in react-native example - @dependabot * chore(deps): bump diff in react-native-firebase example - @dependabot * chore(deps): bump lodash-es from 4.17.4 to 4.17.15 in react-native-firebase example - @dependabot * chore(deps): bump diff from 3.3.0 to 3.5.0 in react-native-firebase example - @dependabot Co-authored-by: Jérémy M <[email protected]> Co-authored-by: Michał Kaczanowicz <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: illuminist <[email protected]>
|
@prescottprue @vicrac
import { combineReducers } from 'redux';
import { firestoreReducer } from 'redux-firestore';
import { firebaseReducer } from 'react-redux-firebase';
interface User { };
interface Schema { };
interface RootState {
// previously
firebase: FirebaseReducer.Reducer<User>;
// change to
firebase: FirebaseReducer.Reducer<Schema, User>;
firestore: FirestoreReducer.Reducer;
}
combineReducers<RootState>({
firebase: firebaseReducer,
firestore: firestoreReducer,
});I admit this change is not too difficult for a Typescript developer to figure out, but documentation with this release would have saved me some debugging time. |
|
Also, |
|
@rscotten Thanks for pointing out - I'm open to a PR if you get a chance |
|
Yeah this was definitely an annoying breaking change to figure out, please put it in the patch notes or something? |
|
@w0nche0l The support for schema was mentioned in the release notes, but the break of types was not intended as part of the change. Instead of noting the workaround I am making the update mentioned by @rscotten (i.e. having Schema be the second generic type). Also, I have been working on updating the typescript example and adding a page to the recipes section of the docs explaining how to pass a schema type when using Typescript. As for the schema handling for Firestore, I'll have to get to that when I can unless someone else wants to make a PR |
* fix(types): add types for `onAttemptCollectionDelete` to fix `implicit any` error (#870) - @macinjoke * fix(populate): handle firestore list type in populate (#871) - @illuminist * fix(types): add missing `onAuthStateChanged` for config object - @illuminist * fix(types): relax typing for `UserProfile` to be generic object - @illuminist * fix(types): make Schema the second generic parameter (#826) * chore(docs): add a typescript page to the recipes section of the docs (explains passing schema to reducer) Co-authored-by: illuminist <[email protected]> Co-authored-by: macinjoke <[email protected]> Co-authored-by: Marko Elez <[email protected]> Co-authored-by: Chris Dzoba <[email protected]>
| } | ||
|
|
||
| export namespace FirebaseReducer { | ||
| export interface Reducer<ProfileType = {}> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is breaking change. The parameter order was changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call out. Yeah, this was in an attempt to have the feature work as originally intended
Description
For now, loose typings for state make it unsafe to use with typescript. I've added additional type parameter to state, defining
Schemafor database. Consider:Now if we create a selector...
we are getting autocompletion!:

... and proper inner type!

Of course, I am open to suggestions, but I literally made the smallest possible change that allowed me to get these features (and not to crash types).