Skip to content

Commit e837383

Browse files
committed
Add notes on duplicate type definitions problem.
1 parent 3bcb564 commit e837383

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Use TypeScript in your Ember 2.x and 3.x apps!
1919
* [Opt-in unsafety for Ember Data lookups](#opt-in-unsafety-for-ember-data-lookups)
2020
* [Type definitions outside `node_modules/@types`](#type-definitions-outside-node_modulestypes)
2121
* [ember-browserify](#ember-browserify)
22+
* ["TypeScript is complaining about multiple copies of the same types"](#typescript-is-complaining-about-multiple-copies-of-the-same-types)
23+
* [Just tell me how to fix it](#just-tell-me-how-to-fix-it)
24+
* [Why is this happening?](#why-is-this-happening)
2225
* [Current limitations](#current-limitations)
2326
* [Some `import`s don't resolve](#some-imports-dont-resolve)
2427
* [Type safety when invoking actions](#type-safety-when-invoking-actions)
@@ -356,6 +359,31 @@ If the `my-module` has types, you will not be able to resolve them this way by d
356359
}
357360
```
358361

362+
### "TypeScript is complaining about multiple copies of the same types!"
363+
364+
You may sometimes see TypeScript errors indicating that you have duplicate type definitions for Ember, Ember Data, etc. This is usually the result of an annoying quirk of the way both npm and yarn resolve your dependencies in their lockfiles.
365+
366+
#### Just tell me how to fix it
367+
368+
There are two options here, neither of them _great_:
369+
370+
* manually edit `yarn.lock` or `package-lock.json` and merge the conflicting
371+
* add a ["resolutions"] key to your `package.json` with the version you want to install of the types you're installing:
372+
373+
```json
374+
{
375+
"resolutions": {
376+
"**/@types/ember": "2.8.8"
377+
}
378+
}
379+
```
380+
381+
["resolutions"]: https://yarnpkg.com/lang/en/docs/selective-version-resolutions/
382+
383+
#### Why is this happening?
384+
385+
If you're using another package which includes these types, and then you trigger an upgrade for your own copy of the type definitions, npm and yarn will both try to preserve the existing installation and simply add a new one for your updated version. In most cases, this is sane behavior, because it prevents transitive dependency breakage hell. However, in the _specific_ case of type definitions, it causes TypeScript to get confused.
386+
359387
## Current limitations
360388

361389
While TS already works nicely for many things in Ember, there are a number of corners where it _won't_ help you out. Some of them are just a matter of further work on updating the [existing typings]; others are a matter of further support landing in TypeScript itself, or changes to Ember's object model.

0 commit comments

Comments
 (0)