diff --git a/packages/@ember/-internals/container/lib/container.ts b/packages/@ember/-internals/container/lib/container.ts index 1b7c596c74e..da224b31077 100644 --- a/packages/@ember/-internals/container/lib/container.ts +++ b/packages/@ember/-internals/container/lib/container.ts @@ -1,8 +1,8 @@ -import { Factory, LookupOptions, Owner, setOwner } from '@ember/-internals/owner'; +import { Factory, FactoryClass, Owner, setOwner } from '@ember/-internals/owner'; import { dictionary, symbol } from '@ember/-internals/utils'; import { assert } from '@ember/debug'; import { DEBUG } from '@glimmer/env'; -import Registry, { DebugRegistry } from './registry'; +import Registry, { DebugRegistry, TypeOptions } from './registry'; interface LeakTracking { hasContainers(): boolean; @@ -143,7 +143,7 @@ export default class Container { @param {String} [options.source] The fullname of the request source (used for local lookup) @return {any} */ - lookup(fullName: string, options: LookupOptions): any { + lookup(fullName: string, options?: TypeOptions): unknown { if (this.isDestroyed) { throw new Error(`Cannot call \`.lookup\` after the owner has been destroyed`); } @@ -206,11 +206,9 @@ export default class Container { @public @method factoryFor @param {String} fullName - @param {Object} [options] - @param {String} [options.source] The fullname of the request source (used for local lookup) @return {any} */ - factoryFor(fullName: string): Factory | undefined { + factoryFor(fullName: string): Factory | undefined { if (this.isDestroyed) { throw new Error(`Cannot call \`.factoryFor\` after the owner has been destroyed`); } @@ -218,7 +216,9 @@ export default class Container { assert('fullName must be a proper full name', this.registry.isValidFullName(normalizedName)); - return factoryFor(this, normalizedName, fullName) as Factory | undefined; + // TODO: This needs to return a Factory to be compatible with Owner. + // We should correctly the types so that this cast is not necessary. + return factoryFor(this, normalizedName, fullName) as Factory; } } @@ -261,7 +261,7 @@ function isInstantiatable(container: Container, fullName: string) { return container.registry.getOption(fullName, 'instantiate') !== false; } -function lookup(container: Container, fullName: string, options: LookupOptions = {}) { +function lookup(container: Container, fullName: string, options: TypeOptions = {}) { let normalizedName = fullName; if ( @@ -277,14 +277,18 @@ function lookup(container: Container, fullName: string, options: LookupOptions = return instantiateFactory(container, normalizedName, fullName, options); } -function factoryFor(container: Container, normalizedName: string, fullName: string) { +function factoryFor( + container: Container, + normalizedName: string, + fullName: string +): FactoryManager | undefined { let cached = container.factoryManagerCache[normalizedName]; if (cached !== undefined) { return cached; } - let factory = container.registry.resolve(normalizedName) as DebugFactory | undefined; + let factory = container.registry.resolve(normalizedName) as DebugFactory | undefined; if (factory === undefined) { return; @@ -442,7 +446,8 @@ export interface LazyInjection { specifier: string; } -declare interface DebugFactory extends Factory { +declare interface DebugFactory + extends Factory { _onLookup?: (fullName: string) => void; _initFactory?: (factoryManager: FactoryManager) => void; _lazyInjections(): { [key: string]: LazyInjection }; @@ -458,7 +463,7 @@ export function setFactoryFor(obj: any, factory: FactoryManager): void obj[INIT_FACTORY] = factory; } -export class FactoryManager { +export class FactoryManager { readonly container: Container; readonly owner: Owner | null; readonly class: Factory & DebugFactory; diff --git a/packages/@ember/-internals/container/lib/registry.ts b/packages/@ember/-internals/container/lib/registry.ts index 5b11d49b083..d976f984756 100644 --- a/packages/@ember/-internals/container/lib/registry.ts +++ b/packages/@ember/-internals/container/lib/registry.ts @@ -79,12 +79,12 @@ export default class Registry implements IRegistry { readonly _failSet: Set; resolver: Resolver | (Resolve & NotResolver) | null; readonly fallback: IRegistry | null; - readonly registrations: { [key: string]: object }; - _localLookupCache: { [key: string]: object }; - readonly _normalizeCache: { [key: string]: string }; - readonly _options: { [key: string]: TypeOptions }; - readonly _resolveCache: { [key: string]: object }; - readonly _typeOptions: { [key: string]: TypeOptions }; + readonly registrations: Record; + _localLookupCache: Record; + readonly _normalizeCache: Record; + readonly _options: Record; + readonly _resolveCache: Record; + readonly _typeOptions: Record; constructor(options: RegistryOptions = {}) { this.fallback = options.fallback || null; @@ -182,7 +182,7 @@ export default class Registry implements IRegistry { @param {Function} factory @param {Object} options */ - register(fullName: string, factory: Factory, options: object = {}): void { + register(fullName: string, factory: Factory, options: TypeOptions = {}): void { assert('fullName must be a proper full name', this.isValidFullName(fullName)); assert(`Attempting to register an unknown factory: '${fullName}'`, factory !== undefined); diff --git a/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts b/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts index 3f164ef7506..2cc64543431 100644 --- a/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts +++ b/packages/@ember/-internals/glimmer/lib/component-managers/curly.ts @@ -133,7 +133,7 @@ export default class CurlyComponentManager if (layout === undefined) { if (layoutName !== undefined) { - let _factory = owner.lookup(`template:${layoutName}`); + let _factory = owner.lookup(`template:${layoutName}`) as TemplateFactory; assert(`Layout \`${layoutName}\` not found!`, _factory !== undefined); factory = _factory; } else { diff --git a/packages/@ember/-internals/glimmer/lib/component.ts b/packages/@ember/-internals/glimmer/lib/component.ts index 9901ba079b2..d838f613beb 100644 --- a/packages/@ember/-internals/glimmer/lib/component.ts +++ b/packages/@ember/-internals/glimmer/lib/component.ts @@ -710,8 +710,8 @@ const Component = CoreView.extend( let owner = getOwner(this); assert('Component is unexpectedly missing an owner', owner); - if (owner.lookup('-environment:main')!.isInteractive) { - this.__dispatcher = owner.lookup('event_dispatcher:main'); + if ((owner.lookup('-environment:main') as Environment)!.isInteractive) { + this.__dispatcher = owner.lookup('event_dispatcher:main') as EventDispatcher; } else { // In FastBoot we have no EventDispatcher. Set to null to not try again to look it up. this.__dispatcher = null; diff --git a/packages/@ember/-internals/glimmer/lib/components/link-to.ts b/packages/@ember/-internals/glimmer/lib/components/link-to.ts index 17aa8eeb239..0320e62a57c 100644 --- a/packages/@ember/-internals/glimmer/lib/components/link-to.ts +++ b/packages/@ember/-internals/glimmer/lib/components/link-to.ts @@ -2,7 +2,8 @@ import { Owner } from '@ember/-internals/owner'; import { Route, RouterState, RoutingService } from '@ember/-internals/routing'; import { isSimpleClick } from '@ember/-internals/views'; import { assert, debugFreeze, inspect, warn } from '@ember/debug'; -import { EngineInstance, getEngineParent } from '@ember/engine'; +import { getEngineParent } from '@ember/engine'; +import EngineInstance from '@ember/engine/instance'; import { flaggedInstrument } from '@ember/instrumentation'; import { action } from '@ember/object'; import { service } from '@ember/service'; diff --git a/packages/@ember/-internals/glimmer/lib/modifiers/action.ts b/packages/@ember/-internals/glimmer/lib/modifiers/action.ts index ec23c0ceff6..aabb2b59c9c 100644 --- a/packages/@ember/-internals/glimmer/lib/modifiers/action.ts +++ b/packages/@ember/-internals/glimmer/lib/modifiers/action.ts @@ -265,7 +265,7 @@ class ActionModifierManager implements InternalModifierManager('event_dispatcher:main'); + let dispatcher = actionState.owner.lookup('event_dispatcher:main') as EventDispatcher; dispatcher?.setupHandlerForEmberEvent(actionState.eventName); } diff --git a/packages/@ember/-internals/glimmer/lib/resolver.ts b/packages/@ember/-internals/glimmer/lib/resolver.ts index 96071ae14c5..ffd80103b21 100644 --- a/packages/@ember/-internals/glimmer/lib/resolver.ts +++ b/packages/@ember/-internals/glimmer/lib/resolver.ts @@ -1,6 +1,7 @@ import { privatize as P } from '@ember/-internals/container'; +import { TypeOptions } from '@ember/-internals/container/lib/registry'; import { ENV } from '@ember/-internals/environment'; -import { Factory, FactoryClass, LookupOptions, Owner } from '@ember/-internals/owner'; +import { Factory, Owner } from '@ember/-internals/owner'; import { assert } from '@ember/debug'; import { _instrumentStart } from '@ember/instrumentation'; import { DEBUG } from '@glimmer/env'; @@ -56,28 +57,24 @@ function instrumentationPayload(name: string) { return { object: `component:${name}` }; } -function componentFor( - name: string, - owner: Owner, - options?: LookupOptions -): Option> { +function componentFor(name: string, owner: Owner): Option> { let fullName = `component:${name}`; - return owner.factoryFor(fullName, options) || null; + return owner.factoryFor(fullName) || null; } -function layoutFor(name: string, owner: Owner, options?: LookupOptions): Option