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
If you're developing an Ember app or addon and _not_ using EmberData (and accordingly not even have the EmberData types installed), you may see an error like this and be confused:
131
-
132
-
```text
133
-
node_modules/@types/ember-data/index.d.ts(920,56): error TS2344: Type 'any' does not satisfy the constraint 'never'.
134
-
```
135
-
136
-
This happens because the types for Ember's _test_ tooling includes the types for EmberData because the `this` value in several of Ember's test types can include a reference to the EmberData `Store` class.
137
-
138
-
**The fix:** add a declaration like this in a new file named `ember-data.d.ts` in your `types` directory:
This works because (a) we include things in your types directory automatically and (b) TypeScript will merge this module and interface declaration with the main definitions for EmberData from DefinitelyTyped behind the scenes.
149
-
150
-
If you're developing an addon and concerned that this might affect consumers, it won't. Your types directory will never be referenced by consumers at all!
Copy file name to clipboardExpand all lines: guides/release/typescript/application-development/addons.md
+7-13
Original file line number
Diff line number
Diff line change
@@ -18,24 +18,19 @@ Project files will be generated with `.ts` extensions instead of `.js`.
18
18
19
19
In addition to the usual packages added with `ember addon`, the following packages will be added at their current "latest" value:
20
20
21
-
-`typescript`
22
-
-`@tsconfig/ember`
23
-
-`@typescript-eslint/*`
24
-
-`@types/ember`
25
-
-`@types/ember-data`
26
-
-`@types/ember__*` – `@types/ember__object` for `@ember/object`, etc.
27
-
-`@types/ember-data__*` – `@types/ember-data__model` for `@ember-data/model`, etc.
28
-
-`@types/qunit`
29
-
-`@types/rsvp`
30
-
31
-
The `typescript` package provides tooling to support TypeScript type checking and compilation. The `@types` packages from [DefinitelyTyped][] provide TypeScript type definitions for all of the Ember and EmberData modules.
21
+
-`typescript` – tooling to support TypeScript type checking and compilation.
22
+
-`@tsconfig/ember` – a shared TypeScript configuration for Ember apps.
23
+
-`@typescript-eslint/*` – ESLint support for TypeScript.
24
+
-`@types/qunit` - TypeScript type definitions for QUnit.
25
+
-`@types/rsvp` - TypeScript type definitions for RSVP.
26
+
-`@warp-drive/core-types` - shared core types, type utilities and constants for the WarpDrive and EmberData packages.
32
27
33
28
<divclass="cta">
34
29
<divclass="cta-note">
35
30
<div class="cta-note-body">
36
31
<div class="cta-note-heading">Zoey says...</div>
37
32
<div class="cta-note-message">
38
-
Ember also publishes its own native types compiled directly from its source code, as described <a href="https://blog.emberjs.com/stable-typescript-types-in-ember-5-1/">in this blog post</a>. For now, we continue to use the <code>@types</code> packages by default for the sake of compatibility with EmberData, because EmberData is not yet compatible with Ember's native official types. However, if you do not use EmberData, we <i>highly</i> recommend following the instructions in that blog post to switch to the native types, which are guaranteed to always be 100% correct and 100% up to date!
33
+
Ember and EmberData publish their own native types compiled directly from their source code, so you do not need to install any <code>@types/ember</code> or <code>@types/ember-data</code> packages. These packages should be considered legacy, are only lightly maintained, and will conflict with the native types.
Copy file name to clipboardExpand all lines: guides/release/typescript/application-development/converting-an-app.md
+58-19
Original file line number
Diff line number
Diff line change
@@ -2,35 +2,47 @@ These directions are for converting an _existing_ Ember app to TypeScript. If yo
2
2
3
3
## Enable TypeScript Features
4
4
5
-
### A Bit of a Hack
5
+
### Install TypeScript and Related Packages
6
6
7
-
Since `ember-cli`_currently_ has no flag to convert your project to TypeScript, we're going to use a bit of a hack and _temporarily_ install the legacy `ember-cli-typescript` addon to complete most of the migration:
7
+
See [Getting Started: Packages to Support TypeScript][packages] for descriptions of these packages.
The `ember-cli-typescript` addon will install _most_ of the necessary packages and create or update _most_ of the necessary files as described in [Getting Started][].
16
+
### Add TypeScript Configuration
17
+
18
+
Add a `tsconfig.json` file to the root of your project. Copy its contents from the [current output from the Ember CLI blueprints][tsconfig.json].
14
19
15
-
You can then immediately remove the `ember-cli-typescript` dependency and follow the rest of this guide.
20
+
### Set Up TypeScript for EmberData
16
21
17
-
### Manually Enable TypeScript Transpilation
22
+
Follow the instructions in the [EmberData Typescript Guides][ED-ts-guides].
23
+
24
+
### Enable TypeScript Transpilation for Builds
18
25
19
26
To enable TypeScript transpilation in your app, simply add the corresponding configuration for Babel to your `ember-cli-build.js` file.
Then, update your `.eslintrc.js` to include the [current output from the Ember CLI blueprints][eslintrc]. You might consider using ESLint [overrides][] configuration to separately configure your JavaScript and TypeScript files during the migration.
77
+
### Configure ESLint
78
+
79
+
Then, update your `eslint.config.mjs` to include the [current output from the Ember CLI blueprints][eslintrc]. You might consider using ESLint [overrides][] configuration to separately configure your JavaScript and TypeScript files during the migration.
80
+
81
+
### Add Initial Type Declarations
82
+
83
+
Add types for your `config/environment.js` file by creating a type declaration file at `app/config/environment.d.ts`. You can find an example file in the [current output from the Ember CLI blueprints][environment.d.ts].
51
84
52
85
## Migrate Existing Code to TypeScript
53
86
@@ -83,23 +116,29 @@ In general, we recommend migrating to Octane idioms before, or in conjunction wi
83
116
84
117
## ember-cli-typescript
85
118
86
-
If you're migrating from `ember-cli-typescript`, particularly an older version, to Ember's out-of-the-box TypeScript support, you may also need to update your `tsconfig.json`. Current versions of `ember-cli-typescript` generate the correct config at installation. You do _not_ need `ember-cli-typescript` installed for new apps or addons.
119
+
The `ember-cli-typescript` package was used to add TypeScript support to Ember apps before Ember's native TypeScript support was available. You do _not_ need `ember-cli-typescript` installed for new apps or addons.
120
+
121
+
If you're migrating from `ember-cli-typescript` to Ember's native TypeScript support, most of your existing configuration will still be relevant. Just read through the steps of this guide and ensure that your config matches the expected config as described above.
0 commit comments