Skip to content

types: make DataSource.stop compatible with LB4#1838

Merged
bajtos merged 1 commit into
masterfrom
fix/stop-typings
Apr 28, 2020
Merged

types: make DataSource.stop compatible with LB4#1838
bajtos merged 1 commit into
masterfrom
fix/stop-typings

Conversation

@bajtos

@bajtos bajtos commented Apr 28, 2020

Copy link
Copy Markdown
Member

This is a follow-up for #1835.

Change the return value of DataSource.stop() from Promise<void> to void | PromiseLike<void> to avoid breaking existing LoopBack 4 applications, where DataSource subclasses are scaffolded with stop(): ValueOrPromise<void>.

Before the change, build of loopback-next was failing with the following errors (see loopbackio/loopback-next#5261)

https://travis-ci.com/github/strongloop/loopback-next/jobs/323793285

> loopback-next@0.1.0 build /home/travis/build/strongloop/loopback-next
> node packages/build/bin/compile-package -b

examples/multi-tenancy/src/datasources/db.datasource.ts:40:3 - error TS2416: Property 'stop' in type 'DbDataSource' is not assignable to the same property in base type 'DataSource'.
  Type '() => ValueOrPromise<void>' is not assignable to type '() => Promise<void>'.
    Type 'ValueOrPromise<void>' is not assignable to type 'Promise<void>'.
      Type 'void' is not assignable to type 'Promise<void>'.

40   stop(): ValueOrPromise<void> {
     ~~~~
(...)

I have manually verified that the new typings are fixing loopback-next build:

$ (cd packages/repository && npm link {path-to-juggler})
$ npm run build

Checklist

👉 Read and sign the CLA (Contributor License Agreement) 👈

  • npm test passes on your machine
  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide
  • Commit messages are following our guidelines

Change the return value of `DataSource.stop()` from `Promise<void>`
to `void | PromiseLike<void>` to avoid breaking existing LoopBack 4
applications, where DataSource subclasses are scaffolded with
`stop(): ValueOrPromise<void>`.

Signed-off-by: Miroslav Bajtoš <mbajtoss@gmail.com>
@bajtos
bajtos merged commit a25df6a into master Apr 28, 2020
@delete-merged-branch
delete-merged-branch Bot deleted the fix/stop-typings branch April 28, 2020 07:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants