从 TypeScript 声明全局命名空间变量 [英] declare global namespace variable from TypeScript

查看:43
本文介绍了从 TypeScript 声明全局命名空间变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在打字稿的全局命名空间中显式声明一个变量?

How to explicitly declare a variable in the global namespace from typescript?

我需要编译器生成以下 javascript 代码:

I need the compiler to generate the following javascript code:

MyExtension = someFunction()

不幸的是,我只能让它生成

unfortunately, I can only have it generate

var MyExtension = someFunction()

这涉及到最新版本的流星包(仍在 rc 中)的问题.Meteor 引入了一种在包中定义命名空间范围的方法——问题是,变量需要在全局命名空间中定义(流星重新路由到它自己的包对象).

This comes to an issue with the latest version (still in rc) of meteor packages. Meteor introduced a way to scope namespaces in packages - the issue is, the variable needs to be defined in the global namespace (which meteor reroutes to its own Package object).

https://www.eventedmind.com/posts/meteor-链接器包命名空间.

是否有某种global 关键字可用或在计划中?

Is there some kind of global keyword available or in the plans?

推荐答案

使用 declare 关键字.这些被称为环境声明.

Use the declare keyword. These are known as ambient declarations.

declare var MyExtentention:any;

这篇关于从 TypeScript 声明全局命名空间变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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