You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Service and controller injections](#service-and-controller-injections)
16
18
*[Ember Data lookups](#ember-data-lookups)
17
19
*[Opt-in unsafety](#opt-in-unsafety)
@@ -38,7 +40,7 @@ ember install ember-cli-typescript@latest
38
40
39
41
All dependencies will be added to your `package.json`, and you're ready to roll! If you're upgrading from a previous release, you should check to merge any tweaks you've made to `tsconfig.json`.
40
42
41
-
In addition to ember-cli-typescript, the following are installed—all at their current "latest" value:
43
+
In addition to ember-cli-typescript, the following are installed—all at their current "latest" value—or generated:
*`types/<app name>/index.d.ts` – the location for any global type declarations you need to write for you own application; see [Global types for your package](#global-types-for-your-package) for information on its default contents and how to use it effectively
53
+
*`types/<app name>/config/environment.d.ts` – a basic set of types defined for the contents of the `config/environment.js` file in your app; see [Environment and configuration typings](#environment-and-configuration-typings) for details
50
54
51
55
### Ember support
52
56
@@ -113,10 +117,30 @@ To make this easier, we're maintaining [a list of addons with known type definit
During installation, we create a `types` directory in the root of your application and add a `"paths"` mapping that includes that directory in any type lookups TypeScript tries to do. This is convenient for a few things:
123
+
124
+
* global types for your package (see the next section)
125
+
* writing types for third-party/`vendor` packages which do not have any types
126
+
* developing types for an addon which you intend to upstream later
127
+
128
+
These are all fallbacks, of course, you should use the types supplied directly with a package
129
+
130
+
#### Global types for your package
131
+
132
+
At the root of your application or addon, we include a `types/<your app>` directory with an `index.d.ts` file in it. Anything which is part of your application but which must be declared globally can go in this file. For example, if you have data attached to the `Window` object when the page is loaded (for bootstrapping or whatever other reason), this is a good place to declare it.
133
+
134
+
In the case of applications (but not for addons), we also automatically include declarations for Ember's prototype extensions in this `index.d.ts` file. If you are [disabling Ember's prototype extensions][disabling], you can remove these declarations; we include them because they're enabled in most Ember applications today.
Along with the @types/ files mentioned above, ember-cli-typescript adds a starter interface for `config/environment.js` in `config/environment.d.ts`. This interface will likely require some changes to match your app.
119
141
142
+
We install this file because the actual `config/environment.js` is (a) not actually identical with the types as you inherit them in the content of an application, but rather a superset of what an application has access to, and (b) not in a the same location as the path at which you look it up. We map it to the lookup path within your `types` directory, and TypeScript resolves it correctly.
143
+
120
144
### Service and controller injections
121
145
122
146
Ember does service and controller lookups with the `inject` helpers at runtime, using the name of the service or controller being injected up as the default value—a clever bit of metaprogramming that makes for a nice developer experience. TypeScript cannot do this, because the name of the service or controller to inject isn't available at compile time in the same way. This means that if you do things the normal Ember way, you will have to specify the type of your service or controller explicitly everywhere you use it.
0 commit comments