Skip to content

Instantly share code, notes, and snippets.

@zkochan
Last active December 1, 2016 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkochan/b4739bbe72dcefbc3cb90956de52fbda to your computer and use it in GitHub Desktop.
Save zkochan/b4739bbe72dcefbc3cb90956de52fbda to your computer and use it in GitHub Desktop.
How to migrate a project to TypeScript
  1. Use lebab to convert your modules to ES2015 modules.
lebab es5.js -o es6.js --transform commonjs
  1. Change the .js extensions to .ts.
  2. Install typescript as a devDependency to your package
npm i -D typescript
  1. Add a tsconfig.json to the root of your package with the following content:
{
  "compilerOptions": {
    "removeComments": false,
    "preserveConstEnums": true,
    "sourceMap": true,
    "declaration": true,
    "noImplicitAny": false,
    "noImplicitReturns": true,
    "suppressImplicitAnyIndexErrors": true,
    "allowSyntheticDefaultImports": true,
    "strictNullChecks": true,
    "target": "es6",
    "outDir": "dist",
    "module": "commonjs",
    "moduleResolution": "node"
  },
  "filesGlob": [
    "src/"
  ]
}
  1. Add a prepublish script task to your package.json:
{
  ...
  "scripts": {
    ...
    "prepublish": "tsc",
    ...
  },
  ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment