将Typescript与Google Apps脚本一起使用 [英] Use Typescript with Google Apps Script

查看:119
本文介绍了将Typescript与Google Apps脚本一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Google Apps Script(GAS)项目中使用Typescript,但是我找不到将我的代码编译成GAS可以接受的内容的方法.

I'd like to use Typescript for my Google Apps Script (GAS) projects, but I can't find a way to compile my code into something that GAS accepts.

GAS不支持导出,并且Typescript似乎不喜欢通过全局范围访问变量(它需要导入/需要,因此需要导出).

GAS doesn't support export, and Typescript seems to dislike accessing variables via the global scope (it wants imports/require, and thus exports).

我正在寻找以下任何我认为可以使我工作的解决方案:

I'm looking for any of the following solutions which I believe would make things work for me:

1)Babel插件或类似的插件可以删除所有Import和Export语句以及它们的属性名(要求我不要使用相同的方法名,而我不会使用相同的方法名.

1) Babel plugin or the like that can remove all the Import and Export statements along with their attributed names (requires that I don't use the same method names, which I don't.

所以:

import MyLibrary from './library';
export function greetJohn() { MyLibrary.greet('John'); }
export default { greetJohn }

成为:

function greetJohn() { greet('John'); }

2)更改打字稿,使其可以看到全局范围

2) Change typescript so that it can see the global scope

3)Babel插件等将所有.ts文件组合为一个.js文件,并通过将每个文件视为对象/函数来转换导入/导出语句.

3) Babel plugin or the like that combines all the .ts files into one .js file and transforms the import/export statements by treating each file like an Object/function.

推荐答案

现在可以使用Typescript来开发Google Apps脚本项目,但这不能直接在Apps脚本编辑器上完成.

Now it's possible to use Typescript to develop Google Apps Script projects but this could not be done directly on the Apps Script Editor.

根据使用TypeScript开发Apps脚本,更简单的方法是使用 clasp .

According to Develop Apps Script using TypeScript the easier way is by using clasp.

相关

这篇关于将Typescript与Google Apps脚本一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆