What is the scope of a type alias?

筅森魡賤 提交于 2019-12-11 03:04:44

问题


What is the scope of a typescript type alias? I have this alias and I think that I might want to declare it globally somehow:

type ResouceResult<T> = T & {
    $promise: ng.IPromise<T>,
    $resolved: boolean
};

回答1:


Section 3.9 of Typescript 1.5 language specification: http://www.typescriptlang.org/Content/TypeScript%20Language%20Specification.pdf

3.9 Type Aliases

A type alias declaration introduces a type alias in the containing module

so module




回答2:


declare it globally

If your file is a global, the type alias is global. If its a module, the type alias is a module.

More on this https://basarat.gitbooks.io/typescript/content/docs/project/modules.html



来源:https://stackoverflow.com/questions/33436192/what-is-the-scope-of-a-type-alias

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!