github / github/codeql

Javascript: How to define an own type and mark its attributes and types

未关闭
#12,524 12 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
JS question
主要语言
CodeQL
星标
10.1k
派生
2.1k
平均合并
2 天 15 小时
30 天内合并 PR
141

描述

I want to define a Foo type in codeql, which has its own attributes and types, which is convenient for subsequent type analysis

For example, I want to find the intAdd function, the wrong call to pass the parameter is not a number

```javascript
// some function will return "Foo"
function getFoo() {
return {
id: 123,
name: "foo",
data: { xxx: "xxx" },
};
}
function createFoo() {
return {
id: 123,
name: "foo",
data: { xxx: "xxx" },
};
}
function getFoos() {
return [
{
id: 123,
name: "foo",
data: { xxx: "xxx" },
},
{
id: 123,
name: "foo",
data: { xxx: "xxx" },
},
];
}

// use the Foo
let a = {};
let f1 = getFoo();
let fs = getFoos();
intAdd(123); // good
intAdd(f1.id); // good
intAdd(f1.name); // bad
intAdd(f1.data); // bad
fs.forEach((f) =>{
intAdd(f.name); // bad
});
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。