TS 中 declare、namespace、.d.ts
machao07 opened this issue · comments
马超 commented
declare
声明文件
不包含实现,它只是类型声明,把声明文件加入到 TypeScript 中
namespace
确保创建的变量不会泄漏至全局命名空间
因此 TypeScript 提供了 namespace 关键字来描述这种分组
namespace Utility {
export function log(msg) {
console.log(msg);
}
export function error(msg) {
console.log(msg);
}
}
// usage
Utility.log('Call me');
Utility.error('maybe');
.d.ts 与 @types
.d.ts
可以在 ts 中调用的 js 的声明文件,主流的库都是 JS编写的,并不支持类型系统
TS 2.0
中使用 @type/...
类型定义, ts将会默认的查看 ./node_modules/@types
区别: