github / github/codeql

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

Open
#12,524 12 comments 0 reactions 0 assignees View on GitHub
JS question
Dominant language
CodeQL
Stars
10.1k
Forks
2.1k
Avg merge
2d 15h
Merged PRs (30d)
141

Description

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
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.