Abbreviate lengthy TypeScript Types

2019-07-31 03:06发布

问题:

I'm developing a Google Apps Script (GAS) using Typescript (via the clasp tool).

I imported type definitions by running npm i -S @types/google-apps-script.

Some types are quite lengthy, for example:

let sheet: GoogleAppsScript.Spreadsheet.Sheet

Is there a way to define an abbreviation within a file? e.g.,

declare Sheet = GoogleAppsScript.Spreadsheet.Sheet

回答1:

You can define new alias type:

type Sheet = GoogleAppsScript.Spreadsheet.Sheet