Skip to content

Commit

Permalink
fix: use typeof operator to check function type (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Jul 29, 2020
1 parent f6e8292 commit 4143afb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/ContainerInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class ContainerInstance {
if (typeof identifierOrServiceMetadata === "object" && (identifierOrServiceMetadata as { service: Token<any> }).service) {
return this.set({ id: (identifierOrServiceMetadata as { service: Token<any> }).service, value: value });
}
if (identifierOrServiceMetadata instanceof Function) {
if (typeof identifierOrServiceMetadata === "function") {
return this.set({ type: identifierOrServiceMetadata, id: identifierOrServiceMetadata, value: value });
}

Expand Down Expand Up @@ -231,7 +231,7 @@ export class ContainerInstance {
if (service.id)
return service.id === identifier;

if (service.type && identifier instanceof Function)
if (service.type && typeof identifier === "function")
return service.type === identifier || identifier.prototype instanceof service.type;

return false;
Expand All @@ -253,7 +253,7 @@ export class ContainerInstance {
return service.id === identifier;
}

if (service.type && identifier instanceof Function)
if (service.type && typeof identifier === "function")
return service.type === identifier; // todo: not sure why it was here || identifier.prototype instanceof service.type;

return false;
Expand Down Expand Up @@ -281,10 +281,10 @@ export class ContainerInstance {
if (service && service.type) {
type = service.type;

} else if (service && service.id instanceof Function) {
} else if (service && typeof service.id === "function") {
type = service.id;

} else if (identifier instanceof Function) {
} else if (typeof identifier === "function") {
type = identifier;

// } else if (identifier instanceof Object && (identifier as { service: Token<any> }).service instanceof Token) {
Expand Down
2 changes: 1 addition & 1 deletion src/decorators/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function Service<T, K extends keyof T>(options?: ServiceOptions<T, K>): F
* Marks class as a service that can be injected using container.
*/
export function Service<T, K extends keyof T>(optionsOrServiceName?: ServiceOptions<T, K>|Token<any>|string|any[]|(() => any), maybeFactory?: (...args: any[]) => any): any {
if (arguments.length === 2 || (optionsOrServiceName instanceof Function)) {
if (arguments.length === 2 || typeof optionsOrServiceName === "function") {
const serviceId = { service: new Token<T>() };
const dependencies = arguments.length === 2 ? optionsOrServiceName as any[] : [];
const factory = arguments.length === 2 ? maybeFactory : optionsOrServiceName as Function;
Expand Down

0 comments on commit 4143afb

Please sign in to comment.