Skip to content

Commit

Permalink
frint-di: Fix Container.get() return type (#414)
Browse files Browse the repository at this point in the history
* frint-di: Fix Container.get() return type

* Make options optional in createContainer() definition

* Updated types on App.get() which uses Container.get()
  • Loading branch information
viacheslaff authored Mar 26, 2018
1 parent eb28525 commit b5435c9
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/frint-cli/src/bin/frint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function run() {
return console.log('Command not available.');
}

return commandApp.get<FrintCliProvider>('execute')();
return (commandApp.get('execute') as FrintCliProvider)();
}

run();
4 changes: 2 additions & 2 deletions packages/frint-cli/src/commands/help.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('frint-cli › commands › help', () => {
const commandApp = rootApp.getAppInstance('help');
const fakeConsole = rootApp.get('console');

commandApp.get<FrintCliProvider>('execute')();
commandApp.get('execute')();

expect(fakeConsole.errors.length).to.equal(1);
expect(fakeConsole.errors[0]).to.contain('Must provide a command name');
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('frint-cli › commands › help', () => {
const commandApp = rootApp.getAppInstance('help');
const fakeConsole = rootApp.get('console');

commandApp.get<FrintCliProvider>('execute')();
commandApp.get('execute')();

expect(fakeConsole.logs.length).to.equal(1);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/frint-cli/src/commands/version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('frint-cli › commands › version', () => {
'{"version": "1.2.3"}'
);

commandApp.get<FrintCliProvider>('execute')();
commandApp.get('execute')();

expect(fakeConsole.logs.length).to.equal(1);
expect(fakeConsole.logs[0]).to.contain('v1.2.3');
Expand Down
4 changes: 2 additions & 2 deletions packages/frint-di/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface Provider {
export interface Container {
getDeps(container: Provider): any;
register(container: Provider): any;
get<T extends Provider>(name: string): T;
get(name: string): any;
}

export interface ContainerOptions {
Expand All @@ -24,6 +24,6 @@ export interface Constructor<T> {
new(): T;
}

export function createContainer(providers: Provider[], options: ContainerOptions): Constructor<Container>;
export function createContainer(providers: Provider[], options?: ContainerOptions): Constructor<Container>;

export function resolveContainer<T>(Container: Constructor<T>): T;
4 changes: 2 additions & 2 deletions packages/frint/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ export class App {
});
}

public get<T extends FrintProvider>(providerName) {
const value = this.container.get<T>(providerName);
public get(providerName) {
const value = this.container.get(providerName);

if (typeof value !== 'undefined') {
return value;
Expand Down

0 comments on commit b5435c9

Please sign in to comment.