Is this a typescript function?

Viewed 55

I was reading the vue-next source code, and came across a line I had a little trouble with. I figure this is because I am new to typescript.

Is this a function? What is it doing?

const isComment = (node: Node): node is Comment =>
  node.nodeType === DOMNodeTypes.COMMENT
2 Answers

Yes. The node is Comment syntax is used to relay the fact that the function's purpose is to check if the passed-in parameter is of a specific type, "Comment" in this case.

node is Comment is a type predicate, where node must be the name of a parameter from the current function signature, each time isComment is called the Typescript narrows the Node type to the Comment one if the parameter is compatible with Node type

Related