Skip to content

Commit

Permalink
fix: remove extra imports for mixin dependencies
Browse files Browse the repository at this point in the history
With the new TypeScript version, it is no longer necessary to manually
import types referenced by mixin classes.

This commit removes those extra imports from the CLI template and
scaffolded "application.ts" files; and also sorts import using VS Code's
feature "Organize imports".

While removing unused imports, I cleaned up few more places where
we were importing extra types.
  • Loading branch information
bajtos authored and raymondfeng committed Aug 25, 2018
1 parent 294c50e commit 35b916b
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 110 deletions.
7 changes: 1 addition & 6 deletions docs/site/Booting-an-Application.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,8 @@ example below)_

### Using the BootMixin

`Booter` and `Binding` types must be imported alongside `BootMixin` to allow
TypeScript to infer types and avoid errors. _If using `tslint` with the
`no-unused-variable` rule, you can disable it for the import line by adding
`// tslint:disable-next-line:no-unused-variable` above the import statement_.

```ts
import {BootMixin, Booter, Binding} from "@loopback/boot";
import {BootMixin} from "@loopback/boot";

class MyApplication extends BootMixin(Application) {
constructor(options?: ApplicationConfig) {
Expand Down
15 changes: 2 additions & 13 deletions docs/site/todo-tutorial-putting-it-together.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,12 @@ artifacts and inject them into our application for use.
#### src/application.ts

```ts
import {BootMixin} from '@loopback/boot';
import {ApplicationConfig} from '@loopback/core';
import {RepositoryMixin} from '@loopback/repository';
import {RestApplication, RestServer} from '@loopback/rest';
import {MySequence} from './sequence';

/* tslint:disable:no-unused-variable */
// Binding and Booter imports are required to infer types for BootMixin!
import {BootMixin, Booter, Binding} from '@loopback/boot';

// juggler imports are required to infer types for RepositoryMixin!
import {
Class,
Repository,
RepositoryMixin,
juggler,
} from '@loopback/repository';
/* tslint:enable:no-unused-variable */

export class TodoListApplication extends BootMixin(
RepositoryMixin(RestApplication),
) {
Expand Down
15 changes: 2 additions & 13 deletions examples/soap-calculator/src/application.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import {BootMixin} from '@loopback/boot';
import {ApplicationConfig, Constructor, Provider} from '@loopback/core';
import {RepositoryMixin} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {MySequence} from './sequence';
import {CalculatorServiceProvider} from './services/calculator.service';

// Binding and Booter imports are required to infer types for BootMixin!
/* tslint:disable:no-unused-variable */
import {BootMixin, Booter, Binding} from '@loopback/boot';

// juggler imports are required to infer types for RepositoryMixin!
import {
Class,
Repository,
RepositoryMixin,
juggler,
} from '@loopback/repository';
/* tslint:enable:no-unused-variable */

export class SoapCalculatorApplication extends BootMixin(
RepositoryMixin(RestApplication),
) {
Expand Down
15 changes: 2 additions & 13 deletions examples/todo-list/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,12 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {BootMixin} from '@loopback/boot';
import {ApplicationConfig} from '@loopback/core';
import {RepositoryMixin} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {MySequence} from './sequence';

/* tslint:disable:no-unused-variable */
// Binding and Booter imports are required to infer types for BootMixin!
import {BootMixin, Booter, Binding} from '@loopback/boot';

// juggler imports are required to infer types for RepositoryMixin!
import {
Class,
Repository,
RepositoryMixin,
juggler,
} from '@loopback/repository';
/* tslint:enable:no-unused-variable */

export class TodoListApplication extends BootMixin(
RepositoryMixin(RestApplication),
) {
Expand Down
17 changes: 3 additions & 14 deletions examples/todo/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {ApplicationConfig, Provider, Constructor} from '@loopback/core';
import {BootMixin} from '@loopback/boot';
import {ApplicationConfig, Constructor, Provider} from '@loopback/core';
import {RepositoryMixin} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {MySequence} from './sequence';
import {GeocoderServiceProvider} from './services';

/* tslint:disable:no-unused-variable */
// Binding and Booter imports are required to infer types for BootMixin!
import {BootMixin, Booter, Binding} from '@loopback/boot';

// juggler imports are required to infer types for RepositoryMixin!
import {
Class,
Repository,
RepositoryMixin,
juggler,
} from '@loopback/repository';
/* tslint:enable:no-unused-variable */

export class TodoListApplication extends BootMixin(
RepositoryMixin(RestApplication),
) {
Expand Down
16 changes: 3 additions & 13 deletions packages/boot/test/fixtures/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,10 @@
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT

import {RestApplication} from '@loopback/rest';
import {ApplicationConfig} from '@loopback/core';
// tslint:disable:no-unused-variable
import {
RepositoryMixin,
Class,
Repository,
juggler,
} from '@loopback/repository';
// tslint:enable:no-unused-variable

// Binding and Booter imports are required to infer types for BootMixin!
// tslint:disable-next-line:no-unused-variable
import {BootMixin, Booter, Binding} from '../../index';
import {RepositoryMixin} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {BootMixin} from '../../index';

export class BooterApp extends RepositoryMixin(BootMixin(RestApplication)) {
constructor(options?: ApplicationConfig) {
Expand Down
19 changes: 4 additions & 15 deletions packages/cli/generators/app/templates/src/application.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import {BootMixin} from '@loopback/boot';
import {ApplicationConfig} from '@loopback/core';
import {RestApplication} from '@loopback/rest';
import {MySequence} from './sequence';

/* tslint:disable:no-unused-variable */
// Binding and Booter imports are required to infer types for BootMixin!
import {BootMixin, Booter, Binding} from '@loopback/boot';
<% if (project.enableRepository) { -%>
// juggler imports are required to infer types for RepositoryMixin!
import {
Class,
Repository,
RepositoryMixin,
juggler,
} from '@loopback/repository';
import {RepositoryMixin} from '@loopback/repository';
<% } -%>
/* tslint:enable:no-unused-variable */
import {RestApplication} from '@loopback/rest';
import {MySequence} from './sequence';

export class <%= project.applicationName %> <% if (!project.enableRepository) {-%>extends BootMixin(RestApplication) {<% } else { -%>extends BootMixin(
RepositoryMixin(RestApplication),
Expand Down
11 changes: 2 additions & 9 deletions packages/repository/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,11 @@ We'll use `BootMixin` on top of `RepositoryMixin` so that Repository bindings
can be taken care of automatically at boot time before the application starts.

```ts
import {BootMixin} from '@loopback/boot';
import {ApplicationConfig} from '@loopback/core';
import {RepositoryMixin} from '@loopback/repository';
import {RestApplication} from '@loopback/rest';
import {db} from './datasources/db.datasource';
/* tslint:disable:no-unused-variable */
import {BootMixin, Booter, Binding} from '@loopback/boot';
import {
RepositoryMixin,
Class,
Repository,
juggler,
} from '@loopback/repository';
/* tslint:enable:no-unused-variable */

export class RepoApplication extends BootMixin(
RepositoryMixin(RestApplication),
Expand Down
3 changes: 0 additions & 3 deletions packages/repository/src/repositories/legacy-juggler-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import {
HasManyRepositoryFactory,
} from './relation.factory';
import {HasManyDefinition} from '../decorators/relation.decorator';
// need the import for exporting of a return type
// tslint:disable-next-line:no-unused-variable
import {HasManyRepository} from './relation.repository';

export namespace juggler {
export import DataSource = legacy.DataSource;
Expand Down
9 changes: 1 addition & 8 deletions packages/repository/test/unit/query/query-builder.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
// License text available at https://opensource.org/licenses/MIT

import {expect} from '@loopback/testlab';
import {
FilterBuilder,
Filter,
WhereBuilder,
Where,
filterTemplate,
isFilter,
} from '../../../';
import {FilterBuilder, WhereBuilder, filterTemplate, isFilter} from '../../../';

describe('WhereBuilder', () => {
it('builds where object', () => {
Expand Down
3 changes: 0 additions & 3 deletions packages/rest/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import {
Send,
} from './types';

// NOTE(bajtos) The following import is required to satisfy TypeScript compiler
// tslint:disable-next-line:no-unused-variable
import {OpenAPIObject} from '@loopback/openapi-v3-types';
import {HttpProtocol} from '@loopback/http-server';
import * as https from 'https';

Expand Down

0 comments on commit 35b916b

Please sign in to comment.