项目作者: markfknight

项目描述 :
Simple TypeScript scratchpad setup for Visual Studio Code
高级语言: TypeScript
项目地址: git://github.com/markfknight/vscode-typescript-scratchpad.git
创建时间: 2017-03-18T15:10:32Z
项目社区:https://github.com/markfknight/vscode-typescript-scratchpad

开源协议:MIT License

下载


VSCode TypeScript Scratchpad

A simple setup for TypeScript coding in VSCode.
The follwing is setup out of the box:

Prerequisites

To start, node is required.

npm (Node Package Manager) or yarn can be used as
package managers.

The TypeScript Compiler (tsc) is included and
not required in your path.

via npm

  1. npm -g install typescript

via yarn

  1. yarn add global typescript

Getting started

Fork the repo and clone to your local machine, open a terminal / command line
and get base packages:

via npm

  1. npm install

via yarn

  1. yarn

The src/index.ts is your entry point, code away! Add additional files to the src
folder and import to your src/index.ts file to use per the hello_world example.

Adding 3rd Party Packages

Open a terminal / command line, add a package:

via npm

  1. npm install packageName --save

via yarn

  1. yarn add packageName

If typings are missing/not included with the base packge, the majority of
popular npm packages have typings defined on npm under the @types scoping.

Install typings as a dev dependancy:

via npm

  1. npm install @types/packageName --save-dev

via yarn

  1. yarn add @types/packageName -D

Linting

The project is setup with Linting via eslint
and typescript-eslint.
If you use VSCode linting feedback should
appear in the editor as you type, you can also run linting on the project:

via npm

  1. npm run lint

via yarn

  1. yarn lint

Testing

The project is setup and configured with
ts-jest to run
Jest tests. Jest tests saved in the src
folder will get picked up if the meet one of the following criteria:

  • ts/tsx files saved in __tests__ folders
  • files meeting the following patterns
    • *.test.ts
    • *.spec.ts

To run tests

via npm

  1. npm test

via yarn

  1. yarn test

There is a pre-test hook that runs tslint
before tests are run.

There is a very useful plugin
Jest
(free), an integrated continuous testing tool that adds test feedback to the
editor and session based test watching.

Another (multi-editor) integrated continuous testing plugin is the renowned
Wallaby.js (paid) that this base setup works out of
the box with.

Building

Running the Build task in VSCode will compile
TypeScript (/src) to es2020 JavaSript (/dist).

Shortcut on Windows/Linux: Ctrl + Shift + B, macOS: Command + Shift + B

Debugging

Set breakpoints in your TS code and press F5 to start the debugger, happy debugging!

Running

To run the your code

via npm

  1. npm start

via yarn

  1. yarn start

This command uses ts-node to run your application in node using your
tsconfig.json compile options, without compiling to JavaScript files.

Running with tests

To run the your code:

via npm

  1. npm run start:test

via yarn

  1. yarn start:test

This runs index.ts file via ts-node after linting and tests are successful.

Live feedback

TS imports will work out of the box with Quokka.js Pro

Customisations

For editor defaults, adjust editor.config.

To change TS linting, adjust .eslintrc.js.

Adjust the settings in tsconfig.json to change the compiled output.