TypeScript Declaration Merging(声明合并)
最近在进行前端开发的时候,为了拓展引用,使用了TS声明合并的特性,完整的了解了一下该特性,特此记录成笔记。声明合并指在TypeScript里面,编译器将两个或者多个独立的相同名称的声明合并到一起。合并后的定义同时包含所有声明。可以理解为声明的拓展 接口合并最常见的合并就是接口合并,接口合并后的成员会整合到一起。 接口中的非函数成员应该是唯一的,如果不是唯一,那他们必须有相同的类型,如果声明了两个同名但是类型不通的非函数成员会报错 对于函数成员而言,每一个同名函数成员都相当于当前函数成员的一个版本,第一个接口A和第二个接口A合并的时候,第二个接口声明对象的优先级会高于第一个 eg: 12345678910interface Cloner { clone(animal: Animal): Animal;}interface Cloner { clone(animal: Sheep): Sheep;}interface Cloner { clone(animal: Dog): Dog; clone(animal: Cat):...
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub. Quick StartCreate a new post1$ hexo new "My New Post" More info: Writing Run server1$ hexo server More info: Server Generate static files1$ hexo generate More info: Generating Deploy to remote sites1$ hexo deploy More info: Deployment
