Duplicate identifier error while creating a class in Typescript

Viewed 274

I'm trying to create a Linked List in Typescript, and I've created a INode interface, and a node class to start it off

interface INode<T> {
  data: T;
  next: INode<T> | null;
}

class Node<T> implements INode<T> {
  public data: T;
  public next: INode<T> | null;
  
  constructor(data: T) {
    this.data = data
    this.next = null
  }
}

The problem is: I'm getting a TS error that keeps saying:

Duplicate identifier "Node"

And based on the code I showed above, there's no duplicate identifier. How can I fix this error?

1 Answers

Your class Node conflicts with the abstract interface provide by the dom Node interface: https://developer.mozilla.org/en-US/docs/Web/API/Node

Either you need to name your class something else or remove dom from your compiler lib (e.g. tsconfig.json) if this is something you don't need.

Related