TypeScript中有严格的类型检查吗?

时间:2019-03-29 11:59:21

标签: typescript

我正在用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);

是否可能出现此错误?如何升级我的示例以获取它?

0 个答案:

没有答案