admin管理员组文章数量:1291762
I thought that an ambient context in TypeScript is designed specifically to hold information about what variables/types/things are out there, and what is their type. So, the code const value = 42
in a .ts
file becomes declare const value: 42
in the output .d.ts
.
But it turns out that declare const value = 42
is also valid.
I tried declare … = 42
and declare …: 42
; both result in the same .js
output, and the .d.ts
output just copies the original source code. I haven't noticed any effects on the behavior of the compiler.
Is there any difference between using a colon and using an equals sign with declare
? The only difference I can think of is that TypeScript-specific operators (42 | 17
, 42 & 17
, keyof 42
) can't be used.
本文标签: typescriptWhat does it mean to use initialization in an ambient contextStack Overflow
版权声明:本文标题:typescript - What does it mean to use initialization in an ambient context? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741541286a2384336.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论