Skip to content

Commit b063b8d

Browse files
authored
Merge branch 'master' into allowSyntheticDefaultImports
2 parents 6460dfa + 99b90fd commit b063b8d

32 files changed

+6045
-184
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
/libpeerconnection.log
1616
npm-debug.log*
1717
testem.log
18-
yarn.lock
1918

2019
# TypeScript
2120
jsconfig.json

README.md

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# ember-cli-typescript
22

3-
[![*nix build status (master)](https://travis-ci.org/typed-ember/ember-cli-typescript.svg?branch=master)](https://travis-ci.org/typed-ember/ember-cli-typescript) [![Windows build status (master)](https://ci.appveyor.com/api/projects/status/i94uv7jgmrg022ho/branch/master?svg=true)](https://ci.appveyor.com/project/chriskrycho/ember-cli-typescript/branch/master)
4-
[![Ember Observer Score](https://emberobserver.com/badges/ember-cli-typescript.svg)](https://emberobserver.com/addons/ember-cli-typescript)
5-
63
Use TypeScript in your Ember 2.x apps!
74

5+
[![*nix build status (master)](https://travis-ci.org/typed-ember/ember-cli-typescript.svg?branch=master)](https://travis-ci.org/typed-ember/ember-cli-typescript) [![Windows build status](https://ci.appveyor.com/api/projects/status/i94uv7jgmrg022ho/branch/master?svg=true)](https://ci.appveyor.com/project/chriskrycho/ember-cli-typescript/branch/master)
6+
[![Ember Observer Score](https://emberobserver.com/badges/ember-cli-typescript.svg)](https://emberobserver.com/addons/ember-cli-typescript)
7+
8+
(👆that failing Travis build [is a lie](https://travis-ci.org/typed-ember/ember-cli-typescript). The Ember CLI issue, related to ember-try, is [here](https://github.com/ember-cli/ember-try/issues/161).)
89

910
## Installing/Upgrading
1011

@@ -14,7 +15,9 @@ Just run:
1415
ember install ember-cli-typescript@1
1516
```
1617

17-
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`.
18+
All dependencies will be added to your `package.json`, and you're ready to roll!
19+
(If you're upgrading from a previous release, you should check to merge any
20+
tweaks you've made to `tsconfig.json`.
1821

1922
In addition to ember-cli-typescript, the following are installed:
2023

@@ -91,11 +94,17 @@ on the background and roadmap for the project.
9194

9295
[typing-your-ember]: http://www.chriskrycho.com/typing-your-ember.html
9396

97+
## Environment configuration typings
98+
99+
Along with the @types/ files mentioned above, ember-cli-typescript adds a
100+
starter interface for `config/environment.js` in `config/environment.d.ts`.
101+
This interface will likely require some changes to match your app.
102+
94103
## :construction: Using ember-cli-typescript with Ember CLI addons
95104

96-
**:warning: Warning: this is *not* currently recommended. This is a WIP part of the
97-
add-on, and it *will* make a dramatic difference in the size of your add-on in
98-
terms of installation. The upcoming 1.1 release will enable a much better
105+
**:warning: Warning: this is *not* currently recommended. This is a WIP part of
106+
the add-on, and it *will* make a dramatic difference in the size of your add-on
107+
in terms of installation. The upcoming 1.1 release will enable a much better
99108
experience for consumers of your addon.**
100109

101110
We're working on making a solution that lets us ship generated typings and
@@ -108,12 +117,6 @@ give users fair warning about the increased size. To enable TypeScript for your
108117
addon, simple move `ember-cli-typescript` from `devDependencies` to
109118
`dependencies` in your `package.json`.
110119

111-
## New modules API
112-
113-
Note: the new modules API is not yet supported by the official typings (which
114-
are distinct from this addon, though we install them). We hope to have support
115-
for them shortly!
116-
117120
## Not (yet) supported
118121

119122
While TS already works nicely for many things in Ember, there are a number of
@@ -123,45 +126,32 @@ landing in TypeScript itself.
123126

124127
[existing typings]: https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/ember
125128

126-
We are hard at work (and would welcome your help!) [writing new typings] for
127-
Ember which can give correct types for Ember's custom object model. If you'd
128-
like to try those out, please see instructions in that repo!
129+
We are hard at work (and would welcome your help!) [writing new
130+
typings][ember-typings] for Ember and the surrounding ecosystem. If you'd like
131+
to try those out, please see instructions in [that repo][ember-typings]!
129132

130-
[writing new typings]: https://github.com/typed-ember/ember-typings
133+
[ember-typings]: https://github.com/typed-ember/ember-typings
131134

132135
Here is the short list of things which do *not* work yet in the version of the
133136
typings published on DefinitelyTyped.
134137

135138
### Some `import`s don't resolve
136139

137140
You'll frequently see errors for imports which TypeScript doesn't know how to
138-
resolve. For example, if you use `htmlbars-inline-precompile`:
141+
resolve. For example, if you use Ember Concurrency today and try to import its
142+
`task` helper:
139143

140144
```typescript
141-
import hbs from 'htmlbars-inline-precompile';
145+
import { task } from 'ember-concurrency';
142146
```
143147

144148
You'll see an error, because there aren't yet type definitions for it. You may
145-
see the same with some addons as well. These won't stop the build from working;
146-
they just mean TypeScript doesn't know where to find those.
149+
see the same with some addons as well. **These won't stop the build from
150+
working;** they just mean TypeScript doesn't know where to find those.
147151

148152
Writing these missing type definitions is a great way to pitch in! Jump in
149153
\#topic-typescript on the Ember Slack and we'll be happy to help you.
150154

151-
### `extends` gives errors
152-
153-
You'll see quite a few errors like this when calling `.extends()` on an existing
154-
Ember type:
155-
156-
> Class 'FooController' incorrectly extends base class 'Controller'.
157-
> Type '{ bar(): void; }' has no properties in common with type 'ActionHash'
158-
159-
This is a symptom of the current, out-of-date types. The new typings we're
160-
working on will solve these.
161-
162-
In the meantime, note that your application will still build just fine even with
163-
these errors... they'll just be annoying.
164-
165155
### Type safety when invoking actions
166156

167157
TypeScript won't detect a mismatch between this action and the corresponding
@@ -188,31 +178,6 @@ Likewise, it won't notice a problem when you use the `send` method:
188178
this.send('turnWheel', 'ALSO-NOT-A-NUMBER');
189179
```
190180

191-
### Type safety with `Ember.get`, `Ember.set`, etc.
192-
193-
When you use `Ember.get` or `Ember.set`, TypeScript won't yet warn you that
194-
you're using the wrong type. So in `foo()` here, this will compile but be
195-
wrong at runtime:
196-
197-
```typescript
198-
Ember.Object.extend({
199-
urls: <string[]> null,
200-
port: 4200, // number
201-
202-
init() {
203-
this._super(...arguments);
204-
this.set('urls', []);
205-
},
206-
207-
foo() {
208-
// TypeScript won't detect these type mismatches
209-
this.get('urls').addObject(51);
210-
this.set('port', '3000');
211-
},
212-
});
213-
```
214-
215-
216181
### The type definitions I need to reference are not in `node_modules/@types`
217182

218183
By default the typescript compiler loads up any type definitions found in

blueprints/ember-cli-typescript/files/app/config/environment.d.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ export default config;
88
* since different ember addons can materialize new entries.
99
*/
1010
declare namespace config {
11-
export var environment: any;
12-
export var modulePrefix: string;
13-
export var podModulePrefix: string;
14-
export var locationType: string;
11+
var environment: any;
12+
var modulePrefix: string;
13+
var podModulePrefix: string;
14+
var locationType: string;
15+
var rootURL: string;
1516
}

blueprints/ember-cli-typescript/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ module.exports = {
2828

2929
locals() {
3030
return {
31-
inRepoAddons: (this.project.pkg['ember-addon'] || {}).paths || []
31+
inRepoAddons: (this.project.pkg['ember-addon'] || {}).paths || [],
3232
};
3333
},
3434

@@ -38,10 +38,10 @@ module.exports = {
3838

3939
afterInstall() {
4040
return this.addPackagesToProject([
41-
{ name: 'typescript', target: '^2.4.2' },
42-
{ name: '@types/ember', target: '^2.7.43' },
43-
{ name: '@types/rsvp', target: '^3.3.0' },
44-
{ name: '@types/ember-testing-helpers' },
41+
{ name: 'typescript', target: 'latest' },
42+
{ name: '@types/ember', target: 'latest' },
43+
{ name: '@types/rsvp', target: 'latest' },
44+
{ name: '@types/ember-testing-helpers', target: 'latest' },
4545
]);
4646
},
4747
};

config/ember-try.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,87 +5,87 @@ module.exports = {
55
name: 'ember-lts-2.4',
66
bower: {
77
dependencies: {
8-
'ember': 'components/ember#lts-2-4'
8+
ember: 'components/ember#lts-2-4',
99
},
1010
resolutions: {
11-
'ember': 'lts-2-4'
12-
}
11+
ember: 'lts-2-4',
12+
},
1313
},
1414
npm: {
1515
devDependencies: {
16-
'ember-source': null
17-
}
18-
}
16+
'ember-source': null,
17+
},
18+
},
1919
},
2020
{
2121
name: 'ember-lts-2.8',
2222
bower: {
2323
dependencies: {
24-
'ember': 'components/ember#lts-2-8'
24+
ember: 'components/ember#lts-2-8',
2525
},
2626
resolutions: {
27-
'ember': 'lts-2-8'
28-
}
27+
ember: 'lts-2-8',
28+
},
2929
},
3030
npm: {
3131
devDependencies: {
32-
'ember-source': null
33-
}
34-
}
32+
'ember-source': null,
33+
},
34+
},
3535
},
3636
{
3737
name: 'ember-release',
3838
bower: {
3939
dependencies: {
40-
'ember': 'components/ember#release'
40+
ember: 'components/ember#release',
4141
},
4242
resolutions: {
43-
'ember': 'release'
44-
}
43+
ember: 'release',
44+
},
4545
},
4646
npm: {
4747
devDependencies: {
48-
'ember-source': null
49-
}
50-
}
48+
'ember-source': null,
49+
},
50+
},
5151
},
5252
{
5353
name: 'ember-beta',
5454
bower: {
5555
dependencies: {
56-
'ember': 'components/ember#beta'
56+
ember: 'components/ember#beta',
5757
},
5858
resolutions: {
59-
'ember': 'beta'
60-
}
59+
ember: 'beta',
60+
},
6161
},
6262
npm: {
6363
devDependencies: {
64-
'ember-source': null
65-
}
66-
}
64+
'ember-source': null,
65+
},
66+
},
6767
},
6868
{
6969
name: 'ember-canary',
7070
bower: {
7171
dependencies: {
72-
'ember': 'components/ember#canary'
72+
ember: 'components/ember#canary',
7373
},
7474
resolutions: {
75-
'ember': 'canary'
76-
}
75+
ember: 'canary',
76+
},
7777
},
7878
npm: {
7979
devDependencies: {
80-
'ember-source': null
81-
}
82-
}
80+
'ember-source': null,
81+
},
82+
},
8383
},
8484
{
8585
name: 'ember-default',
8686
npm: {
87-
devDependencies: {}
88-
}
89-
}
90-
]
87+
devDependencies: {},
88+
},
89+
},
90+
],
9191
};

config/environment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
'use strict';
33

44
module.exports = function(/* environment, appConfig */) {
5-
return { };
5+
return {};
66
};

index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const path = require('path');
55
const SilentError = require('silent-error');
66
const TsPreprocessor = require('./lib/typescript-preprocessor');
77

8-
98
module.exports = {
109
name: 'ember-cli-typescript',
1110

@@ -18,18 +17,23 @@ module.exports = {
1817

1918
this.ui.writeInfoLine(
2019
'Skipping TypeScript preprocessing as there is no tsconfig.json. ' +
21-
'(If this is during installation of the add-on, this is as expected. If it is ' +
22-
'while building, serving, or testing the application, this is an error.)'
20+
'(If this is during installation of the add-on, this is as expected. If it is ' +
21+
'while building, serving, or testing the application, this is an error.)'
2322
);
2423
return;
2524
}
2625

2726
try {
28-
registry.add('js', new TsPreprocessor({
29-
ui: this.ui
30-
}));
27+
registry.add(
28+
'js',
29+
new TsPreprocessor({
30+
ui: this.ui,
31+
})
32+
);
3133
} catch (ex) {
32-
throw new SilentError(`Failed to instantiate TypeScript preprocessor, probably due to an invalid tsconfig.json. Please fix or run \`ember generate ember-cli-typescript\`.\n${ex}`);
34+
throw new SilentError(
35+
`Failed to instantiate TypeScript preprocessor, probably due to an invalid tsconfig.json. Please fix or run \`ember generate ember-cli-typescript\`.\n${ex}`
36+
);
3337
}
3438
},
3539
};

known-typings.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Known Typings
2+
3+
This is a list of all known typings specific to the Ember.js ecosystem. (You'll of
4+
course find many other modules with their own typings out there.)
5+
6+
Don't see an addon you use listed here? You might be the one to write them! Check
7+
out [this blog post] or [this quest issue] for tips on how to do it, and feel free
8+
to ask for help in the [Ember Community Slack] ([get an invite]).
9+
10+
[this blog post]: http://www.chriskrycho.com/2017/typing-your-ember-part-5.html
11+
[this quest issue]: https://github.com/typed-ember/ember-typings/issues/14
12+
[Ember Community Slack]: https://embercommunity.slack.com/
13+
[get an invite]: https://ember-community-slackin.herokuapp.com/
14+
15+
## Integrated in the addon
16+
17+
18+
19+
## DefinitelyTyped (`@types`)
20+
21+
For addons which do not have types shipped with the addon directly, you may be
22+
able

lib/typescript-preprocessor.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,7 @@ class TypeScriptPreprocessor {
5050
});
5151
tsc.setDiagnosticWriter(this.ui.writeWarnLine.bind(this.ui));
5252

53-
const ts = debugTree(
54-
tsc,
55-
`${this._tag}`
56-
);
53+
const ts = debugTree(tsc, `${this._tag}`);
5754

5855
// Put everything together.
5956
return mergeTrees([js, ts], {

0 commit comments

Comments
 (0)