关于ts:什么是-TypeScript-的-Module-Augmentation
在进入模块裁减之前,让咱们看看一些 TypeScript 合并准则,这些准则将随着咱们的提高而变得有用。 TypeScript 反对创立同名的 class 和 interface: class Food { cheese: string;}interface Food { bacon: string;}const food = new Food();food.bacon = "nice bacon";food.cheese = "sweet cheese";console.log(food); // {bacon: "nice bacon", cheese: "sweet cheese"}在咱们下面的例子中,咱们能够看到,即便在 Food 类中只申明了 cheese,食物变量也蕴含 bacon 和 cheese。 这是因为,接口与类合并了。 但如果 interface 里蕴含的是办法,后果又如何? class Food { cheese: string;}interface Food { bacon: string; bake(item: string);}const food = new Food();food.bake("cake"); // Error: food.bake is not a function然而,bake 办法会在intelliSense 的帮忙下显示在food 变量上,因为Food 类和接口Food 将合并,调用bake 办法会导致谬误,因为接口只蕴含申明而不蕴含实现。 为了解决这个问题,咱们能够将bake的实现增加到Food原型中。 ...