我正在尝试用打字稿写一个通用的链表,但是兼容的电话签名有一些问题。我刚接触打字稿,我不知道自己做错了什么。
我正在使用-target es2017选项编译以下代码。
class Node<T>
{
private _data : T;
private _prev : Node<T> | null;
private _next : Node<T> | null;
public constructor(data : T,prev = null,next = null)
{
this._data = data;
this._prev = prev;
this._next = next;
}
public get data() : T
{
return this._data;
}
public get prev() : Node<T> | null
{
return this._prev;
}
public get next() : Node<T> | null
{
return this._next;
}
public set setData(data : T)
{
this._data = data;
}
public set setPrev(node : Node<T> | null)
{
this._prev = node;
}
public set setNext (node : Node<T> | null)
{
this._next = node;
}
}
export default class LinkedList<T>
{
private front : Node<T> | null;
private back : Node<T> | null;
public constructor()
{
this.front = null;
this.back = null;
}
push(data : T) : void
{
let newNode = new Node<T>(data);
if(this.back)
{
(this.back)!.setNext(newNode);
newNode.setPrev(this.back!);
}
else
{
this.front = newNode;
this.back = newNode;
}
}
}
\
“ Cannot invoke an expression whose type lacks a call signature. Type 'Node <T>' has no compatible call signatures.
”
这是我在编译时遇到的错误。