Avraam Mavridis
Avraam Mavridis

Reputation: 8920

Property attributes is missing in interface declaration

I have a list of nodes, which I have declare as

const node7 = { value: -50000, next: undefined };
const node6 = { value: 5, next: node7 };
const node5 = { value: 9, next: node6 };
const node4 = { value: 1, next: node5 };
const node3 = { value: -16, next: node4 };
const node2 = { value: 36, next: node3 };
const node1 = { value: 3, next: node2 };
const head = { value: 16, next: node1 };

I created an interface like

interface Node {
  value: number,
  next: Node | undefined
}

And my method looks like

function shortList(head: Node){
  ...
}

Typescript is complaining that

Argument of type '{ value: number; next: { value: number; next: { value: number; next: { value: number; next: { val...' is not assignable to parameter of type 'Node'.
  Property 'attributes' is missing in type '{ value: number; next: { value: number; next: { value: number; next: { value: number; next: { val...

What I am doing wrong?

Upvotes: 1

Views: 305

Answers (1)

Daniel Rosenwasser
Daniel Rosenwasser

Reputation: 23463

There's a global type named Node that refers to the DOM's Node.

That interface of yours is actually merging with that global declaration of Node. What you will need to do is either

  • Export it so that the containing file becomes a module, and your Node doesn't merge with the global Node.
  • Rename it entirely (e.g. MyNode)

Future advice

Sorry about the confusion there! Something that would have hinted at this was if you tried finding all references to Node in your editor. Beyond that, this is something you really do need to read up about to know about the language.

Upvotes: 1

Related Questions