Skip to content

Commit

Permalink
Merge pull request #342 from zb-sj/fix/aliasTo
Browse files Browse the repository at this point in the history
Match parameter types of `aliasTo` from `container.resolve`
  • Loading branch information
jeffijoe committed Oct 12, 2023
2 parents 983935b + cb55556 commit 924ce76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/__tests__/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,15 @@ describe('registrations', () => {
})

describe('aliasTo', () => {
it('returns the aliased dependency', () => {
it('returns the string aliased dependency', () => {
container.register({ val: asValue(123), aliasVal: aliasTo('val') })
expect(container.resolve('aliasVal')).toBe(123)
})

it('returns the symbol aliased dependency', () => {
const symbol = Symbol()
container.register({ [symbol]: asValue(123), aliasVal: aliasTo(symbol) })
expect(container.resolve('aliasVal')).toBe(123)
})
})
})
4 changes: 3 additions & 1 deletion src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ export function asClass<T = {}>(
/**
* Resolves to the specified registration.
*/
export function aliasTo<T>(name: string): Resolver<T> {
export function aliasTo<T>(
name: Parameters<AwilixContainer['resolve']>[0]
): Resolver<T> {
return {
resolve(container) {
return container.resolve(name)
Expand Down

0 comments on commit 924ce76

Please sign in to comment.