How is IntelliJi detecting objects attributes

Hi,

 

I have this Nodejs express code...

 


app.post('/user', async (req, res) =>
{
console.log("save user");
if(AccessManager.checkAccess(req, res, ["user_edit"]))
{
const session = req.session;
if (session && session.user)
{
try
{
const user = req.body.user;

await dbCon.queryDB(`BEGIN`, null);

await dbCon.queryDB(
`INSERT INTO users (sso, name, language, active, last_update_date, last_update_by)
VALUES ($1, $2, $3, $4, NOW(), $5)
ON CONFLICT (sso) DO UPDATE SET name = $2, language = $3, active = $4, last_update_date = NOW(), last_update_by = $5`,
[user.sso, user.name, user.language, user.active, session.user.sso]);

Intelliji is here giving a warning

"unresolved variable sso" for the user.sso as the first insert value

but not for name, language and active.

Why are these attributes ok, but sso not? I would understand if it would find no attributes because its coming from a JSON object from the POST body, or if it doesn't care about all. But only one is not ok that's what I don't understand.

 

评论操作 固定链接

The IDE indeed can't resolve the fields using static code analysis as this data is only available in runtime; so it tries 'week' resolving - props are resolved from the project index by name only. You must have the name, etc. fields defined somewhere in your code and/or libraries...

 You can let the IDE know what your runtime data looks like using JSDoc annotations -this would help to avoid this `weak` resolving. See https://youtrack.jetbrains.com/issue/WEB-17419#comment=27-1058451, https://intellij-support.jetbrains.com/hc/en-us/community/posts/206349469-disable-unresolved-variable-on-json-object-received-by-ajax-call for possible workarounds

1

请先登录再写评论。