Skip to content

Commit

Permalink
Merge branch 'master' into allowSyntheticDefaultImports
Browse files Browse the repository at this point in the history
  • Loading branch information
chriskrycho authored Nov 13, 2017
2 parents 6460dfa + 99b90fd commit b063b8d
Show file tree
Hide file tree
Showing 32 changed files with 6,045 additions and 184 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
/libpeerconnection.log
npm-debug.log*
testem.log
yarn.lock

# TypeScript
jsconfig.json
85 changes: 25 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# ember-cli-typescript

[![*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)
[![Ember Observer Score](https://emberobserver.com/badges/ember-cli-typescript.svg)](https://emberobserver.com/addons/ember-cli-typescript)

Use TypeScript in your Ember 2.x apps!

[![*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)
[![Ember Observer Score](https://emberobserver.com/badges/ember-cli-typescript.svg)](https://emberobserver.com/addons/ember-cli-typescript)

(👆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).)

## Installing/Upgrading

Expand All @@ -14,7 +15,9 @@ Just run:
ember install ember-cli-typescript@1
```

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`.
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`.

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

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

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

## Environment configuration typings

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.

## :construction: Using ember-cli-typescript with Ember CLI addons

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

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

## New modules API

Note: the new modules API is not yet supported by the official typings (which
are distinct from this addon, though we install them). We hope to have support
for them shortly!

## Not (yet) supported

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

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

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

[writing new typings]: https://github.com/typed-ember/ember-typings
[ember-typings]: https://github.com/typed-ember/ember-typings

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

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

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

```typescript
import hbs from 'htmlbars-inline-precompile';
import { task } from 'ember-concurrency';
```

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

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

### `extends` gives errors

You'll see quite a few errors like this when calling `.extends()` on an existing
Ember type:

> Class 'FooController' incorrectly extends base class 'Controller'.
> Type '{ bar(): void; }' has no properties in common with type 'ActionHash'
This is a symptom of the current, out-of-date types. The new typings we're
working on will solve these.

In the meantime, note that your application will still build just fine even with
these errors... they'll just be annoying.

### Type safety when invoking actions

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

### Type safety with `Ember.get`, `Ember.set`, etc.

When you use `Ember.get` or `Ember.set`, TypeScript won't yet warn you that
you're using the wrong type. So in `foo()` here, this will compile but be
wrong at runtime:

```typescript
Ember.Object.extend({
urls: <string[]> null,
port: 4200, // number

init() {
this._super(...arguments);
this.set('urls', []);
},

foo() {
// TypeScript won't detect these type mismatches
this.get('urls').addObject(51);
this.set('port', '3000');
},
});
```


### The type definitions I need to reference are not in `node_modules/@types`

By default the typescript compiler loads up any type definitions found in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ export default config;
* since different ember addons can materialize new entries.
*/
declare namespace config {
export var environment: any;
export var modulePrefix: string;
export var podModulePrefix: string;
export var locationType: string;
var environment: any;
var modulePrefix: string;
var podModulePrefix: string;
var locationType: string;
var rootURL: string;
}
10 changes: 5 additions & 5 deletions blueprints/ember-cli-typescript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {

locals() {
return {
inRepoAddons: (this.project.pkg['ember-addon'] || {}).paths || []
inRepoAddons: (this.project.pkg['ember-addon'] || {}).paths || [],
};
},

Expand All @@ -38,10 +38,10 @@ module.exports = {

afterInstall() {
return this.addPackagesToProject([
{ name: 'typescript', target: '^2.4.2' },
{ name: '@types/ember', target: '^2.7.43' },
{ name: '@types/rsvp', target: '^3.3.0' },
{ name: '@types/ember-testing-helpers' },
{ name: 'typescript', target: 'latest' },
{ name: '@types/ember', target: 'latest' },
{ name: '@types/rsvp', target: 'latest' },
{ name: '@types/ember-testing-helpers', target: 'latest' },
]);
},
};
68 changes: 34 additions & 34 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,87 @@ module.exports = {
name: 'ember-lts-2.4',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-4'
ember: 'components/ember#lts-2-4',
},
resolutions: {
'ember': 'lts-2-4'
}
ember: 'lts-2-4',
},
},
npm: {
devDependencies: {
'ember-source': null
}
}
'ember-source': null,
},
},
},
{
name: 'ember-lts-2.8',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-8'
ember: 'components/ember#lts-2-8',
},
resolutions: {
'ember': 'lts-2-8'
}
ember: 'lts-2-8',
},
},
npm: {
devDependencies: {
'ember-source': null
}
}
'ember-source': null,
},
},
},
{
name: 'ember-release',
bower: {
dependencies: {
'ember': 'components/ember#release'
ember: 'components/ember#release',
},
resolutions: {
'ember': 'release'
}
ember: 'release',
},
},
npm: {
devDependencies: {
'ember-source': null
}
}
'ember-source': null,
},
},
},
{
name: 'ember-beta',
bower: {
dependencies: {
'ember': 'components/ember#beta'
ember: 'components/ember#beta',
},
resolutions: {
'ember': 'beta'
}
ember: 'beta',
},
},
npm: {
devDependencies: {
'ember-source': null
}
}
'ember-source': null,
},
},
},
{
name: 'ember-canary',
bower: {
dependencies: {
'ember': 'components/ember#canary'
ember: 'components/ember#canary',
},
resolutions: {
'ember': 'canary'
}
ember: 'canary',
},
},
npm: {
devDependencies: {
'ember-source': null
}
}
'ember-source': null,
},
},
},
{
name: 'ember-default',
npm: {
devDependencies: {}
}
}
]
devDependencies: {},
},
},
],
};
2 changes: 1 addition & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
'use strict';

module.exports = function(/* environment, appConfig */) {
return { };
return {};
};
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const path = require('path');
const SilentError = require('silent-error');
const TsPreprocessor = require('./lib/typescript-preprocessor');


module.exports = {
name: 'ember-cli-typescript',

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

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

try {
registry.add('js', new TsPreprocessor({
ui: this.ui
}));
registry.add(
'js',
new TsPreprocessor({
ui: this.ui,
})
);
} catch (ex) {
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}`);
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}`
);
}
},
};
22 changes: 22 additions & 0 deletions known-typings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Known Typings

This is a list of all known typings specific to the Ember.js ecosystem. (You'll of
course find many other modules with their own typings out there.)

Don't see an addon you use listed here? You might be the one to write them! Check
out [this blog post] or [this quest issue] for tips on how to do it, and feel free
to ask for help in the [Ember Community Slack] ([get an invite]).

[this blog post]: http://www.chriskrycho.com/2017/typing-your-ember-part-5.html
[this quest issue]: https://github.com/typed-ember/ember-typings/issues/14
[Ember Community Slack]: https://embercommunity.slack.com/
[get an invite]: https://ember-community-slackin.herokuapp.com/

## Integrated in the addon



## DefinitelyTyped (`@types`)

For addons which do not have types shipped with the addon directly, you may be
able
5 changes: 1 addition & 4 deletions lib/typescript-preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ class TypeScriptPreprocessor {
});
tsc.setDiagnosticWriter(this.ui.writeWarnLine.bind(this.ui));

const ts = debugTree(
tsc,
`${this._tag}`
);
const ts = debugTree(tsc, `${this._tag}`);

// Put everything together.
return mergeTrees([js, ts], {
Expand Down
Loading

0 comments on commit b063b8d

Please # to comment.