Skip to content
Use TypeScript in your Ember.js apps!
TypeScript JavaScript HTML Other
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github chore: use Node 10 for CI Jan 20, 2020
.vscode feat: drop support for node 6 May 3, 2019
blueprint-files/ember-cli-typescript feat: enable decorators in tsconfig blueprint Jul 17, 2019
config chore(docs): set addon-docs root url to '' for custom domain Dec 7, 2019
test-fixtures/skeleton-app Merge branch 'master' into build-code-typescript-setup Sep 18, 2018
tests Merge pull request #1026 from MrChocolatine/patch-2 Jan 22, 2020
ts fix: issue a warning if we detect a .js/.ts file collision Jan 20, 2020
vendor Initial Commit from Ember CLI v2.10.0 Dec 3, 2016
.bowerrc Initial Commit from Ember CLI v2.10.0 Dec 3, 2016
.editorconfig Initial Commit from Ember CLI v2.10.0 Dec 3, 2016
.ember-cli Initial Commit from Ember CLI v2.10.0 Dec 3, 2016
.eslintignore Enable ESLint with our current rule set for .ts files Sep 21, 2018
.eslintrc.js feat: drop support for node 6 May 3, 2019
.gitignore ci(azure): linux, compatibility, firefox testing in Azure Pipelines Apr 1, 2019
.npmignore feature(deps): add ember-cli-addon-docs Mar 11, 2019
.prettierignore chore(tools): add prettier with prettier-eslint Apr 16, 2019
.watchmanconfig Initial Commit from Ember CLI v2.10.0 Dec 3, 2016
CHANGELOG.md chore: release v3.1.3 Jan 22, 2020
CODE_OF_CONDUCT.md Add CODE_OF_CONDUCT.md Feb 12, 2018
LICENSE.md Initial Commit from Ember CLI v2.10.0 Dec 3, 2016
README.md ci: update README to reference GH Actions Nov 20, 2019
commitlint.config.js ci: ensure commitlint uses the correct config Dec 2, 2019
debug.sh Copied over from ember-cli-typify Dec 4, 2016
ember-cli-build.js chore(tools): add prettier with prettier-eslint Apr 16, 2019
index.js Rewrite addon main to register Babel plugins Oct 24, 2018
is_md_only.sh disable skip on azure Oct 26, 2018
known-typings.md Update Slack to Discord Sep 18, 2018
package.json chore(deps): update typescript-eslint monorepo to v2.20.0 Feb 17, 2020
register-ts-node.js test: fix node tests when run locally with ts-node Jul 16, 2019
renovate.json chore: remove v2 branch from renovate config Mar 13, 2019
testem.js ci(azure): linux, compatibility, firefox testing in Azure Pipelines Apr 1, 2019
tsconfig.json feat: remove MU support from the default blueprint Aug 27, 2019
yarn.lock chore(deps): update typescript-eslint monorepo to v2.20.0 Feb 17, 2020

README.md

ember-cli-typescript

Use TypeScript in your Ember 2.x and 3.x apps!

Actions Status Ember Observer Score

Documentation

This README focuses on basic information about setting up and using the addon. For more details, see the documentation, which includes:

  • troubleshooting tips
  • a walkthrough for using TypeScript with Ember effectively
  • guides for publishing addons written in TypeScript
  • more details on how the addon sets up your project during installation

…and much more!

Usage

Installation and Setup

You can simply ember install the dependency like normal:

ember install ember-cli-typescript@latest

All dependencies will be added to your package.json, and you're ready to roll! If you're upgrading from a previous release, see below! you should check to merge any tweaks you've made to tsconfig.json.

Upgrading from 1.x

There are a number of important changes between ember-cli-typescript v1 and v2, which mean the upgrade process is straightforward but specific:

  1. Update ember-cli-babel. Fix any problems introduced during the upgrade.
  2. Update ember-decorators. Fix any problems introduced during the upgrade.
  3. Update ember-cli-typescript. Follow the detailed upgrade guide below to fix discrepancies between Babel and TypeScript's compiled output.

If you deviate from this order, you are likely to have a much more difficult time upgrading!

Update ember-cli-babel

ember-cli-typescript requires ember-cli-babel at version 7.1.0 or above, which requires ember-cli 2.13 or above. It also requires @babel/core 7.2.0 or higher.

The recommended approach here is to deduplicate existing installations of the dependency, remove and reinstall ember-cli-babel to make sure that all its transitive dependencies are updated to the latest possible, and then to deduplicate again.

If using yarn:

npx yarn-deduplicate
yarn remove ember-cli-babel
yarn add --dev ember-cli-babel
npx yarn-deduplicate

If using npm:

npm dedupe
npm uninstall ember-cli-babel
npm install --save-dev ember-cli-babel
npm dedupe

Note: If you are also using ember-decorators—and specifically the babel-transform that gets added with it—you will need update @ember-decorators/babel-transforms as well (anything over 3.1.0 should work):

ember install ember-decorators@^3.1.0 @ember-decorators/babel-transforms@^3.1.0

Update ember-decorators

Follow the same process of deduplication, reinstallation, and re-deduplication as described for ember-cli-babel above. This will get you the latest version of ember-decorators and, importantly, its @ember-decorators/babel-transforms dependency.

Update ember-cli-typescript

Now you can simply ember install the dependency like normal:

ember install ember-cli-typescript@latest

Note: To work properly, starting from v2, ember-cli-typescript must be declared as a dependency, not a devDependency for addons. With ember install this migration will be automatically handled for you.

If you choose to make the upgrade manually with yarn or npm, here are the steps you need to follow:

  1. Remove ember-cli-typescript from your devDependencies.

    With yarn:

    yarn remove ember-cli-typescript

    With npm:

    npm uninstall ember-cli-typescript
  2. Install the latest of ember-cli-typescript as a dependency:

    With yarn:

    yarn add ember-cli-typescript@latest

    With npm:

    npm install --save ember-cli-typescript@latest
  3. Run ember generate:

    ember generate ember-cli-typescript
Account for addon build pipeline changes

Since we now integrate in a more traditional way into Ember CLI's build pipeline, there are two changes required for addons using TypeScript.

  • Addons can no longer use .ts in app, because an addon's app directory gets merged with and uses the host's (i.e. the other addon or app's) preprocessors, and we cannot guarantee the host has TS support. Note that .ts will continue to work for in-repo addons because the app build works with the host's (i.e. the app's, not the addon's) preprocessors.

  • Similarly, apps must use .js to override addon defaults in app, since the different file extension means apps no long consistently "win" over addon versions (a limitation of how Babel + app merging interact).

Account for TS → Babel issues

ember-cli-typescript v2 uses Babel to compile your code, and the TypeScript compiler only to check your code. This makes for much faster builds, and eliminates the differences between Babel and TypeScript in the build output that could cause problems in v1. However, because of those differences, you’ll need to make a few changes in the process of upgrading.

  • const enum is not supported at all. You will need to replace all uses of const enum with simply enum or constants.

  • Using ES5 getters or settings with this type annotations is not supported through at least Babel 7.3. However, they should also be unnecessary with ES6 classes, so you can simply remove the this type annotation.

  • Trailing commas after rest function parameters (function foo(...bar[],) {}) are disallowed by the ECMAScript spec, so Babel also disallows them.

  • Re-exports of types have to be disambiguated to be types, rather than values. Neither of these will work:

    export { FooType } from 'foo';
    import { FooType } from 'foo';
    export { FooType };

    In both cases, Babel attempts to emit a value export, not just a type export, and fails because there is no actual value to emit. You can do this instead as a workaround:

    import * as Foo from 'foo';
    export type FooType = Foo.FooType;

Getting Help

When seeking help, you should first consider what you need, and which aspect of the Ember+TypeScript ecosystem your issue pertains to.

💬 Getting Started

We have a channel (#e-typescript) on the Ember Community Discord server where you can ask about getting started, good resources for self-directed learning and more.

📚 Issues With Ember Type Definitions

If you've found that some of the Ember type information is missing things, or is incorrect in some way, please first ensure you're using the latest version of the packages this addon installs. Although StackOverflow and Discuss are not the advised places to report problems, you may find an answer there.

If you don't find an answer, please open an enhancement request or bug report in this project.

⚙️ Issues With Adding TypeScript Support To Apps and Addons

If you run into a problem with the way TypeScript is compiled in Ember apps (i.e., a broccoli error message, incorrect build output, etc...), please first check StackOverflow and Discuss, as you may find an answer.

If you don't find an answer, please open an enhancement request or bug report in this project.

Issues With Linting TypeScript

The TypeScript compiler does some very basic linting of your code, but most developers use (and Microsoft now officially recommends) ESLint.

One sure way to tell which tool is generating an error message is that Linters like ESLint or TSLint will always mention their name, and the name of the pertinent rule, when it alerts you to a violation.

For example, in VS Code, you might see a popover with this message:

[eslint] variable name must be in lowerCamelCase, PascalCase or UPPER_CASE (variable-name)

Here, variable-name is the name of the rule, and [eslint] is the source of the rule.

Supported Ember and TypeScript versions

ember-cli-typescript runs its test suite against Ember CLI current and beta. It's also in active use in several large applications. Any breakage for upcoming releases should be detected and fixed ahead of those releases, but you can help us guarantee that by running your own Ember.js+TypeScript app with beta and canary turned on and let us know if you run into issues with upcoming Ember.js releases.

This library supports the current version of TypeScript TS Version and at least one previous minor or major release. In other words, if 3.4 is the latest release, we do support 3.4.x, 3.3.x, and might support 3.2.x as well. (The test suite only runs against the current release and next branch, but the TS versions do not affect the build process in the same way they do type definitions.)

Installing from git

This addon uses TypeScript for its own implementation, so if you install ember-cli-typescript from git rather than from the npm registry, you won't get compiled .js files. To get everything working, you can install ts-node as a project dependency, and ember-cli-typescript will ensure it's registered correctly to transpile source files as needed.

You can’t perform that action at this time.