TS 中文文档 TS 中文文档
指南
GitHub (opens new window)
指南
GitHub (opens new window)
  • 入门教程

    • TypeScript 手册
    • 基础知识
    • 日常类型
    • 类型缩小
    • 更多关于函数
    • 对象类型
    • 从类型创建类型
    • 泛型
    • Keyof 类型运算符
    • Typeof 类型运算符
    • 索引访问类型
    • 条件类型
    • 映射类型
    • 模板字面类型
    • 类
    • 模块
  • 参考手册

  • 项目配置

gts


Google TypeScript Style


GitHub Actions

gts is Google's TypeScript style guide, and the configuration for our formatter, linter, and automatic code fixer. No lint rules to edit, no configuration to update, no more bike shedding over syntax.

To borrow from standardjs :

No configuration. The easiest way to enforce consistent style in your project. Just drop it in.
Automatically format code. Just run gts fix and say goodbye to messy or inconsistent code.
Catch style issues & programmer errors early. Save precious code review time by eliminating back-and-forth between reviewer & contributor.
Opinionated, but not to a fault. We recommend you use the default configuration, but if you needto customize compiler or linter config, you can.

Under the covers, we use eslint to enforce the style guide and provide automated fixes, and prettier to re-format code.

Getting Started


The easiest way to get started is to run:

  1. ``` shell
  2. npx gts init
  3. ```

How it works


When you run the npx gts init command, it's going to do a few things for you:

Adds an opinionated tsconfig.json file to your project that uses the Google TypeScript Style.
Adds the necessary devDependencies to your package.json.
Adds scripts to your package.json :
lint : Lints and checks for formatting problems.
fix : Automatically fixes formatting and linting problems (if possible).
clean : Removes output files.
compile : Compiles the source code using TypeScript compiler.
pretest, posttest and prepare : convenience integrations.

If a source folder is not already present it will add a default template project.

Individual files


The commands above will all run in the scope of the current folder.  Some commands can be run on individual files:

  1. ``` shell
  2. gts lint index.ts
  3. gts lint one.ts two.ts three.ts
  4. gts lint *.ts
  5. ```

Working with eslint


Under the covers, we use eslint to enforce the style guide and provide automated fixes, and prettier to re-format code. To use the shared eslint configuration, create an .eslintrc in your project directory, and extend the shared config:

  1. ``` yaml
  2. ---
  3. extends:
  4.   - './node_modules/gts'
  5. ```

If you don't want to use the gts CLI, you can drop down to using the module as a basic eslint config, and just use the eslint cli:

  1. ``` sh
  2. $ eslint --fix

  3. ```

This opens the ability to use the vast eslint ecosystem including custom rules, and tools like the VSCode plugin for eslint:

https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint

Badge


Show your love for gts and include a badge!

  1. ``` lisp
  2. [![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet.svg)](https://github.com/google/gts)
  3. ```

Supported Node.js Versions


Our client libraries follow the Node.js release schedule. Libraries are compatible with all current activeand maintenanceversions of Node.js.

License


Apache-2.0

Made with ❤️by the Google Node.js team.

NOTE: This is not an official Google product.

Last Updated: 2023-09-03 17:10:52