Last active
October 23, 2021 11:19
-
-
Save MrChocolatine/39d2eb10c54c7ea66cd1e6de7b1fcc56 to your computer and use it in GitHub Desktop.
Ember.js – Collection of TypeScript types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type EmberApp from '@ember/application'; | |
import type { A as EmberArray } from '@ember/array'; | |
import type { Registry as ControllerRegistry } from '@ember/controller'; | |
import type { RouteModel } from '@ember/routing/router-service'; | |
// --- Glimmer Components | |
interface IGlimmerConstructorOwner extends EmberApp {} | |
/** | |
* Might not really be necessary since Ember.js Glimmer components already have their class field | |
* `args` bound to the generic type parameter passed to their class. | |
*/ | |
type TGlimmerConstructorParams<T> = [ IGlimmerConstructorOwner, T ]; | |
// | |
// --- Ember Array | |
// | |
/** | |
* https://api.emberjs.com/ember/3.28/classes/Ember.NativeArray | |
*/ | |
type EmberNativeArray = ReturnType<typeof EmberArray>; | |
// | |
// --- Ember Data | |
// | |
type EmberPromiseObject<T extends object> = EmberDS.PromiseObject<T>; | |
// --- Ember Routes | |
/** | |
* For now, the `Transition` type is not currently exposed as a public type so a workaround is to | |
* reuse the type returned by Ember's internal methods. More information here: | |
* https://github.com/typed-ember/ember-cli-typescript/blob/ecb513be474b6db641c0aa36b176a8351eb4ed14/docs/ember/routes.md | |
*/ | |
type RouteTransition = ReturnType<EmberRouter['transitionTo']>; | |
/** | |
* Types for the parameters of Routes' method `setupController()` | |
* | |
* Usage: | |
* | |
* ```ts | |
* import Route from '@ember/routing/route'; | |
* | |
* export default class MyRoute extends Route { | |
* setupController(...params: TSetupControllerParams<'my_controller'>) { | |
* super.setupController(...params) | |
* // params[ 0 ] will be the linked Controller | |
* } | |
* } | |
* | |
* On the Controller side: | |
* | |
* ```ts | |
* import Controller from '@ember/controller'; | |
* | |
* export default class MyController extends Controller { | |
* ... | |
* } | |
* | |
* declare module '@ember/controller' { | |
* interface Registry { | |
* my_controller: MyController; | |
* } | |
* } | |
* ``` | |
*/ | |
type TSetupControllerParams<K extends keyof ControllerRegistry> = [ | |
ControllerRegistry[ K ], | |
RouteModel, | |
RouteTransition | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment