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 incompatibility issue between ES6 Promise and Bluebird in Typescript definitions #442

Merged
merged 1 commit into from
Jan 5, 2019

Conversation

snnsnn
Copy link
Contributor

@snnsnn snnsnn commented Jan 4, 2019

📝 Description

I added async started and stopped functions to my service schema but Typescript gives the error below:

import http from 'http';
import { ServiceSchema } from 'moleculer';

const serviceSchema: ServiceSchema = {
  name: 'www',

  settings: {
    port: 3000,
  },

  created() {
    this.server = http.createServer(this.httpHandler);
  },

  async started() {
    this.server.listen(this.settings.port);
  },

  async stopped() {
    this.server.close();
  },

  methods: {
    httpHandler(req: any, res: any) {
      res.end('Hello Moleculer!');
    },
  },
};

Here is the ts error:

Type '() => Promise<void>' is not assignable to type '() => Bluebird<void>'.
  Type 'Promise<void>' is not assignable to type 'Bluebird<void>'.
    Property 'caught' is missing in type 'Promise<void>'.
Type '() => Promise<void>' is not assignable to type '() => Bluebird<void>'.
  Type 'Promise<void>' is not assignable to type 'Bluebird<void>'.

Bluebird itself implements PromiseLike interface, so I thought It would be good choice to use PromiseLike instead of Bluebird to remove incompatibility. Or we could use union type, maybe?

🎯 Relevant issues

💎 Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

🏁 Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code

@coveralls
Copy link

coveralls commented Jan 4, 2019

Pull Request Test Coverage Report for Build 1627

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 92.277%

Totals Coverage Status
Change from base Build 1622: 0.01%
Covered Lines: 4721
Relevant Lines: 4894

💛 - Coveralls

@icebob icebob requested a review from faeron January 4, 2019 19:28
@icebob
Copy link
Member

icebob commented Jan 4, 2019

@faeron @rmccallum81 @ryanm-pm please review it.

index.d.ts Outdated Show resolved Hide resolved
…finitions

Typescript gives error with the following code:

async started() {
    this.server.listen(this.settings.port);
},
async stopped() {
    this.server.close();
},

Here is the ts error:

Type '() => Promise<void>' is not assignable to type '() => Bluebird<void>'.
  Type 'Promise<void>' is not assignable to type 'Bluebird<void>'.
    Property 'caught' is missing in type 'Promise<void>'.

Bluebird itself implements PromiseLike interface, so I thought It would be good choice to use PromiseLike instead of Bluebird to remove incompatibility. Or we could use union type, maybe?
@icebob icebob merged commit 959b978 into moleculerjs:master Jan 5, 2019
@icebob
Copy link
Member

icebob commented Jan 5, 2019

Thank you

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.

None yet

4 participants