Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions text/0821-public-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Introduce public import locations for type-only imports which have previously ha
- [`getOwner` and `setOwner`](#getowner-and-setowner)
- [`RouteInfo`](#routeinfo)
- [`RouteInfoWithAttributes`](#routeinfowithattributes)
- [`Resolver`](#resolver)
- [How we teach this](#how-we-teach-this)
- [`Owner`](#owner-1)
- [`Transition`, `RouteInfo`, and `RouteInfoWithAttributes`](#transition-routeinfo-and-routeinfowithattributes)
Expand Down Expand Up @@ -392,6 +393,33 @@ function takesRouteInfoWithAttributes(routeInfoWithAttributes) {
```


### `Resolver`

The resolver is a contract implemented by libraries outside Ember itself, such as `ember-resolver`, `ember-strict-resolver`, and any number of custom resolvers which exist in apps across the ecosystem. It has never had public documentation, but is fully public API. It is a user-constructible interface with the following definition (using the `Factory` and `FullName` types exported from the new `@ember/owner` module):

```ts
export type KnownForTypeResult<Name extends string> = {
[fullName in `${Name}:${string}`]: boolean | undefined;
};

export interface Resolver {
knownForType?: <Name extends string>(type: Name) => KnownForTypeResult<Name>;
lookupDescription?: (fullName: FullName) => string;
makeToString?: (factory: Factory<object>, fullName: FullName) => string;
normalize?: (fullName: FullName) => string;
resolve(name: string): Factory<object> | object | undefined;
}
```

The `KnownForTypeResult` utility type associated with it is also available as a named export. Unfortunately, due to currently limitations with TypeScript, you will generally have to *cast* to it, but it provides some type safety to callers, because it will *only* allow types corresponding to the passed string if users pass a string literal.

Both are available as named, type-only, user-constructible interfaces from `@ember/owner`:

```ts
import { Resolver, KnownForTypeResult } from '@ember/owner';
```


## How we teach this

These concepts all already exist, but need updates to and in some cases wholly new pages in Ember's API docs.
Expand Down