Skip to content

Commit

Permalink
feat: allow to pass type of embedded options
Browse files Browse the repository at this point in the history
  • Loading branch information
MrChocolatine committed Oct 18, 2021
1 parent 8d0672e commit 6a8e29f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions addon/services/embedded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ import ObjectProxy from '@ember/object/proxy'
import { getOwner } from '@ember/application'
import { assert } from '@ember/debug'

export default class EmbeddedService extends ObjectProxy {
type AnyObject = Record<string, unknown>

export default class EmbeddedService<
EmbeddedOptions extends AnyObject = AnyObject
> extends ObjectProxy<EmbeddedOptions> {

constructor() {
super(...arguments) // eslint-disable-line prefer-rest-params

const factoryName = 'config:embedded'
const factory: Record<string, unknown> | undefined = getOwner(this).factoryFor(factoryName)
const factory: { class: EmbeddedOptions } | undefined = getOwner(this).factoryFor(factoryName)

assert(
`The factory "${factoryName}" could not be found.`,
typeof factory === 'object'
)

// eslint-disable-next-line @typescript-eslint/ban-types
this.content = factory.class as object
this.content = factory.class
}

}
Expand Down

0 comments on commit 6a8e29f

Please sign in to comment.