pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21k stars 1.02k forks source link

es6-proimise module causes typescript build errors #28

Closed thani-sh closed 7 years ago

thani-sh commented 7 years ago

When using with Typescript, the "es6-promise" module causes build errors. For an example, when calling doc.save() we get this error.

[ts]
Type 'Promise<boolean>' is not assignable to type 'Promise<boolean>'. Two different types with this name exist, but they are unrelated.
  Types of property 'then' are incompatible.
    Type '{ <U>(onFulfilled?: (value: boolean) => U | Thenable<U>, onRejected?: (error: any) => U | Thenabl...' is not assignable to type '{ (onfulfilled?: (value: boolean) => boolean | PromiseLike<boolean>, onrejected?: (reason: any) =...'.
      Type 'Promise<any>' is not assignable to type 'Promise<boolean>'.
        Types of property 'then' are incompatible.
          Type '{ <U>(onFulfilled?: (value: any) => U | Thenable<U>, onRejected?: (error: any) => U | Thenable<U>...' is not assignable to type '{ (onfulfilled?: (value: boolean) => boolean | PromiseLike<boolean>, onrejected?: (reason: any) =...'.
            Type 'Promise<any>' is not assignable to type 'Promise<any>'. Two different types with this name exist, but they are unrelated.
              Property '[Symbol.toStringTag]' is missing in type 'Promise<any>'.

As a temporary solution, we can avoid the error with type assertions. I was wondering whether there's a better way to fix this.

pubkey commented 7 years ago

Hi @mnmtanish sry for answering so late. Where did you get this error? I dont get it on the ng2-example of rxdb. Which typescript-version do you use?

thani-sh commented 7 years ago

I got this error on Angular v2.0 and Typescript v1.8 I'll try it again using a newer version of typescript.

thani-sh commented 7 years ago

I'm sorry for the delay. I tried it again with TypeScript v2.0.9. This time I got this error:

Argument of type 'Promise<RxCollection>' is not assignable to parameter of type 'Promise<RxCollection>'.
  Property '[Symbol.toStringTag]' is missing in type 'Promise<RxCollection>'.

The code is something like this:

let collectionPromise: Promise<RxCollection>;
collectionPromise = db.collection('test-collection');
labibramadhan commented 7 years ago

i got the same issue here, any news?

labibramadhan commented 7 years ago

here is my fixes:

  1. on typescript compiler options, set moduleResolution to node and use es5 lib instead of es2015 (i don't know the different). then, install these typings: dt~es6-promise and dt~es6-collections by using command:

    typings install dt~es6-promise and dt~es6-collections --global --save
  2. on typescript compiler options, don't use/set the lib and moduleResolution properties, but still need to install dt~es6-promise and dt~es6-collections as well

pubkey commented 7 years ago

In v3, the polyfills etc. will not be included, which will fix this issue. Until then, you have to stick to the workarround. I'm sorry.

Itrulia commented 7 years ago

@labibramadhan es2015 is ES6.

Also Angular 2 should not be used with Typescript < 2 and if you need Promise in Angular 2 you should use the node typings from @types/node

In Typescript 2 do not use the typings module! Use @types alongside typeRoots in your tsconfig.json

pubkey commented 7 years ago

Closing this since no response. It should work in RxDB v3 now, reopen if you think otherwise.