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