Skip to content
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

Fix TypeScript Definitions for RxQuery #368

Merged
merged 5 commits into from
Nov 21, 2017
Merged

Fix TypeScript Definitions for RxQuery #368

merged 5 commits into from
Nov 21, 2017

Conversation

FlorianKoerner
Copy link
Contributor

RxQuery must differ between model and result to get typeof working. And where also allows a key from the model.

@ihadeed
Copy link
Contributor

ihadeed commented Nov 19, 2017

Ahh good call. I just looked through the code and realized it doesn't make sense. .find() wouldn't be able to get the keys from the model since we're passing an array as a type.

@ihadeed
Copy link
Contributor

ihadeed commented Nov 19, 2017

SyncOptions interface in rx-collection.d.ts need to be changed.

The query property has the type RxQuery<any> assigned to it. Needs to be changed to RxQuery<any, any>.

Alternatively, we can remove <any> from there, and provide default types to RxQuery class declaration:

export declare class RxQuery<RxDocumentType = any, RxQueryResult = any> {

@FlorianKoerner
Copy link
Contributor Author

@ihadeed Thanks for the hint. Fixed.

@pubkey
Copy link
Owner

pubkey commented Nov 20, 2017

Thx @FlorianKoerner for the PR. The ci is now working again, please merge the master into this PR.

I see one more problem with nested documents. For example the following does not work:

type DocType = {
  age: number,
  nestedObject: {
    foo: string,
    bar: number
  }
};
const myCollection: RxCollection<DocType> = await myDb.collection({
  name: 'humans',
  schema: {},
  autoMigrate: false,
});

const query = myCollection.findOne().where('nestedObject.foo').eq('foobar');

Results int:

Argument of type '"nestedObject.foo"' is not assignable to parameter of type '"collection" | "deleted" | "$" | "deleted$" | "synced$" | "resync" | "primary" | "get$" | "get" |...'. (2345)

@FlorianKoerner
Copy link
Contributor Author

FlorianKoerner commented Nov 20, 2017

@pubkey solved "nestedObject.foo" with keyof RxDocumentType | string. So you will get an autocompletion, but you can also use other values.

@pubkey pubkey merged commit c4b439e into pubkey:master Nov 21, 2017
@pubkey
Copy link
Owner

pubkey commented Nov 21, 2017

Thx @FlorianKoerner for the great work. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants