我正在用TypeScript编写一些库,并且我想保护我的方法的调用免受错误含义数据的影响。让我们看下一个例子:
type BookId = number;
type AuthorId = number;
BooksService.getById(bookId: BookId): Book {
// ...
};
let authorId: AuthorId;
// I need to get some type error in next lene, because getById() expect receive BookId, not AuthorId:
book = BooksService.getById(authorId);
是否可能出现此错误?如何升级我的示例以获取它?