Issue
Consider this function,
sampleFunction(val :string | Node){
if(typeof(val) === 'string'){
val = this.getNode(val) as Node;
}
const innerFunction = () => {
...
still the type of val is string | Node
...
}
}
How to convert the type from string | Node to just Node ?
Thanks
Solution
The type of val is still string | Node
, even though you assigned a Node
to it since val can contain string
or Node
. Assign the value to a new const (nodeVal
perhaps) and you will be sorted.
Answered By - Leon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.