Hi,
a subflow has the environment variable List
set to type JSON. The value of this variable is set to:
["foo","bar"]
The variable is retrieved in a function node inside the subflow via env.get()
. When I hover over the get
in the integrated monaco editor, the online help shows up and tells me that this function returns a string
.
But with the lines:
node.warn(typeof env.get('List'));
node.warn(Array.isArray(env.get('List')));
I get: "object"
and true
.
When I then try to iterate through the array by typing
for (let i in env.get('List'))
the editor marks env.get('List')
with this error:
The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type 'string'.(2407)
That's true, if env.get()
would really return a string, but it doesn't. If I ignore the warning and deploy anyway, the code works as expected.
I guess the functions return value was updated at some time, but the definition, the editor uses, was not?
node-red v3.0.2
node.js v16.19.0
Here's a sample (sub)flow:
Example flow:
[
{
"id": "85f46028b8243fab",
"type": "subflow",
"name": "Subflow 1",
"info": "",
"category": "",
"in": [
{
"x": 120,
"y": 60,
"wires": [
{
"id": "c9861e59b0f13953"
}
]
}
],
"out": [],
"env": [
{
"name": "List",
"type": "json",
"value": ""
}
],
"meta": {},
"color": "#DDAA99"
},
{
"id": "c9861e59b0f13953",
"type": "function",
"z": "85f46028b8243fab",
"name": "function 1",
"func": "let List = env.get('List');\nnode.warn(typeof List);\nnode.warn(Array.isArray(List));\nnode.warn(List);\nfor (let i in List)\n node.warn(List[i]);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 240,
"y": 60,
"wires": [
[]
]
},
{
"id": "3c7ce0954fc376d7",
"type": "subflow:85f46028b8243fab",
"z": "d49e15e1b5f5352d",
"name": "",
"env": [
{
"name": "List",
"value": "[\"foo\",\"bar\"]",
"type": "json"
}
],
"x": 620,
"y": 180,
"wires": []
},
{
"id": "da28e302f3f3b142",
"type": "inject",
"z": "d49e15e1b5f5352d",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 460,
"y": 180,
"wires": [
[
"3c7ce0954fc376d7"
]
]
}
]