Create a New TypeScript Application
To start a new Ember project with TypeScript, add the --typescript
flag when you run ember new
:
ember new my-typescript-app --typescript
Using the --typescript
flag changes the output of ember new
in a few ways:
TypeScript Project Files
Project files will be generated with .ts
extensions instead of .js
.
Packages to Support TypeScript
In addition to the usual packages added with ember new
, the following packages will be added at their current "latest" value:
typescript
@tsconfig/ember
@typescript-eslint/*
@types/ember
@types/ember-data
@types/ember__*
–@types/ember__object
for@ember/object
, etc.@types/ember-data__*
–@types/ember-data__model
for@ember-data/model
, etc.@types/qunit
@types/rsvp
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.
Files and Config to Support TypeScript
In addition to the usual files added with ember new
, we also add:
tsconfig.json
– configuration to set up TypeScript for your projecttypes/global.d.ts
– the location for any global type declarations you need to writeapp/config/environment.d.ts
– a basic set of types defined for the contents of yourconfig/environment.js
file
Additionally:
package.json
will have alint:types
script to check types with the command line.ember-cli-build.js
will be configured to transform TypeScript at build-time..ember-cli
hasisTypeScriptProject
set to true, which will force the blueprint generators to generate TypeScript rather than JavaScript by default..eslintrc.js
will be configured for TypeScript.
Convert an Existing App to TypeScript
To convert an existing app to TypeScript, you'll need to make the changes described above manually (for now). To facilitate this, we've included a guide here.