diff --git a/type-tests/preview/@ember/owner-tests.ts b/type-tests/preview/@ember/owner-tests.ts index 4effdfb996b..15ad10010d0 100644 --- a/type-tests/preview/@ember/owner-tests.ts +++ b/type-tests/preview/@ember/owner-tests.ts @@ -1,4 +1,11 @@ -import Owner, { Factory, FactoryManager, FullName, RegisterOptions } from '@ember/owner'; +import Owner, { + Factory, + FactoryManager, + FullName, + RegisterOptions, + Resolver, + KnownForTypeResult, +} from '@ember/owner'; import { expectTypeOf } from 'expect-type'; // Just a class we can construct in the Factory and FactoryManager tests @@ -53,6 +60,19 @@ expectTypeOf(aFactoryManager.create(goodPojo)).toEqualTypeOf(); // @ts-expect-error aFactoryManager.create(badPojo); +// ----- Resolver ----- // +declare let resolver: Resolver; +expectTypeOf().toEqualTypeOf<((fullName: FullName) => string) | undefined>(); +expectTypeOf().toEqualTypeOf< + ((fullName: FullName) => string) | undefined +>(); +expectTypeOf(resolver.resolve('some-name')).toEqualTypeOf | undefined>(); +const knownForFoo = resolver.knownForType?.('foo'); +expectTypeOf(knownForFoo).toEqualTypeOf | undefined>(); +expectTypeOf(knownForFoo?.['foo:bar']).toEqualTypeOf(); +// @ts-expect-error +knownForFoo?.['blah']; + // This one is last so it can reuse the bits from above! // ----- Owner ----- // declare let owner: Owner; diff --git a/types/preview/@ember/-internals/resolver.d.ts b/types/preview/@ember/-internals/resolver.d.ts deleted file mode 100644 index 9bb05c01fce..00000000000 --- a/types/preview/@ember/-internals/resolver.d.ts +++ /dev/null @@ -1,35 +0,0 @@ -declare module '@ember/-internals/resolver' { - /** - * @module - * @private This is not a public API module, and in fact ***there is no such - * module at runtime***. This module exists only to provide a public API for - * `Resolver`, which will get a dedicated home as part of Ember's public API - * via a future RFC. As an end user, if you need access to `Resolver` for now - * you should ordinarily get it via `ember-resolver`. - */ - - import EmberObject from '@ember/object'; - import type { Factory, FullName } from '@ember/owner'; - - export type KnownForTypeResult = { - [fullName in `${Type}:${string}`]: boolean | undefined; - }; - - /** - * A `Resolver` is the mechanism responsible for looking up code in your - * application and converting its naming conventions into the actual classes, - * functions, and templates that Ember needs to resolve its dependencies, for - * example, what template to render for a given route. It is a system that helps - * the app resolve the lookup of JavaScript modules agnostic of what kind of - * module system is used, which can be AMD, CommonJS or just plain globals. It - * is used to lookup routes, models, components, templates, or anything that is - * used in your Ember app. - */ - export interface Resolver extends EmberObject { - knownForType?: (type: TypeName) => KnownForTypeResult; - lookupDescription?: (fullName: FullName) => string; - makeToString?: (factory: Factory, fullName: FullName) => string; - normalize?: (fullName: FullName) => string; - resolve(name: string): Factory | object | undefined; - } -} diff --git a/types/preview/@ember/application/index.d.ts b/types/preview/@ember/application/index.d.ts index 4965e875f58..9fe576425c9 100644 --- a/types/preview/@ember/application/index.d.ts +++ b/types/preview/@ember/application/index.d.ts @@ -5,9 +5,8 @@ declare module '@ember/application' { import { EventDispatcherEvents } from '@ember/application/types'; import Router from '@ember/routing/router'; import Registry from '@ember/application/-private/registry'; - import type { Resolver } from '@ember/-internals/resolver'; import { AnyFn } from 'ember/-private/type-utils'; - import Owner from '@ember/owner'; + import Owner, { Resolver } from '@ember/owner'; import type GlimmerComponent from '@glimmer/component'; import EmberObject from '@ember/object'; diff --git a/types/preview/@ember/debug/container-debug-adapter.d.ts b/types/preview/@ember/debug/container-debug-adapter.d.ts index edc16cc568b..94cc571f9a3 100644 --- a/types/preview/@ember/debug/container-debug-adapter.d.ts +++ b/types/preview/@ember/debug/container-debug-adapter.d.ts @@ -1,5 +1,5 @@ declare module '@ember/debug/container-debug-adapter' { - import type { Resolver } from '@ember/-internals/resolver'; + import type { Resolver } from '@ember/owner'; /** * The ContainerDebugAdapter helps the container and resolver interface diff --git a/types/preview/@ember/engine/index.d.ts b/types/preview/@ember/engine/index.d.ts index 561e251d620..be32ad3ba9b 100644 --- a/types/preview/@ember/engine/index.d.ts +++ b/types/preview/@ember/engine/index.d.ts @@ -3,7 +3,7 @@ declare module '@ember/engine' { import type RegistryProxyMixin from '@ember/engine/-private/registry-proxy-mixin'; import type Initializer from '@ember/engine/-private/types/initializer'; import type EngineInstance from '@ember/engine/instance'; - import type { Resolver } from '@ember/-internals/resolver'; + import type { Resolver } from '@ember/owner'; /** * The `Engine` class contains core functionality for both applications and diff --git a/types/preview/@ember/owner/index.d.ts b/types/preview/@ember/owner/index.d.ts index 31ca3476d4c..09cbd8b53a3 100644 --- a/types/preview/@ember/owner/index.d.ts +++ b/types/preview/@ember/owner/index.d.ts @@ -97,6 +97,36 @@ declare module '@ember/owner' { readonly class: Factory; } + /** + * A record mapping all known items of a given type: if the item is known it + * will be `true`; otherwise it will be `false` or `undefined`. + */ + export type KnownForTypeResult = { + [FullName in `${Type}:${string}`]: boolean | undefined; + }; + + /** + * A `Resolver` is the mechanism responsible for looking up code in your + * application and converting its naming conventions into the actual classes, + * functions, and templates that Ember needs to resolve its dependencies, for + * example, what template to render for a given route. It is a system that helps + * the app resolve the lookup of JavaScript modules agnostic of what kind of + * module system is used, which can be AMD, CommonJS or just plain globals. It + * is used to lookup routes, models, components, templates, or anything that is + * used in your Ember app. + * + * This interface represents the contract a custom resolver must implement. Most + * apps never need to think about this: the application's resolver is supplied by + * `ember-resolver` in the default blueprint. + */ + export interface Resolver { + resolve: (name: string) => Factory | object | undefined; + knownForType?: (type: Type) => KnownForTypeResult; + lookupDescription?: (fullName: FullName) => string; + makeToString?: (factory: Factory, fullName: FullName) => string; + normalize?: (fullName: FullName) => string; + } + // Don't export things unless we *intend* to. export {}; } diff --git a/types/preview/index.d.ts b/types/preview/index.d.ts index e887be9736a..b106926d952 100644 --- a/types/preview/index.d.ts +++ b/types/preview/index.d.ts @@ -23,8 +23,6 @@ import './ember'; import './ember/-private/type-utils'; -import './@ember/-internals/resolver'; - import './@ember/application'; import './@ember/application/-private/event-dispatcher'; import './@ember/application/-private/registry';