下面是类型别名部分正式文档中的示例。
type LinkedList<T> = T & { next: LinkedList<T> };
interface Person {
name: string;
}
var people: LinkedList<Person>;
var s = people.name;
//var s = people.next.name;
//var s = people.next.next.name;
//var s = people.next.next.next.name;当我尝试这个例子时,它会生成以下错误:
TypeError: Cannot read property 'name' of undefined人是linkList型的。如何正确填写人员链接列表?
发布于 2016-09-22 18:39:07
您应该给它赋值,仅仅声明类型是不够的。例如:
var people: LinkedList<Person> = {name: "Alf", next: {name: "Tim", next: null}};https://stackoverflow.com/questions/39646245
复制相似问题