mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-20 12:00:53 +08:00
Added test for adding object literals as models
This commit is contained in:
@@ -131,6 +131,11 @@ function test_collection() {
|
||||
var book1: Book = new Book({ title: "Title 1", author: "Mike" });
|
||||
books.add(book1);
|
||||
|
||||
// Objects can be added to collection by casting to model type.
|
||||
// Compiler will check if object properties are valid for the cast.
|
||||
// This gives better type checking than declaring an `any` overload.
|
||||
books.add(<Book>{ title: "Title 2", author: "Mikey" });
|
||||
|
||||
var model: Book = book1.collection.first();
|
||||
if (model !== book1) {
|
||||
throw new Error("Error");
|
||||
|
||||
Reference in New Issue
Block a user