Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to make getType() work in TypeScript #16849

Open
jpoly1219 opened this issue Jun 26, 2024 · 5 comments
Open

Question: How to make getType() work in TypeScript #16849

jpoly1219 opened this issue Jun 26, 2024 · 5 comments
Labels
question Further information is requested

Comments

@jpoly1219
Copy link

jpoly1219 commented Jun 26, 2024

Hello, I was hoping to get some help about using getType() in Typescript files. The docs say the following:

Static type information
Static type information and global name binding is available for projects with “full” TypeScript extraction enabled. This option is enabled by default when you create databases with the CodeQL CLI.

I don't seem to be able to get any calls to .getType() to work. Am I missing a setup process to enable the "full" TypeScript extraction? How should I set that up?

For more context, the following query does not return anything:

from Type t
select t

I believe this is the reason why .getType() isn't returning anything, since there are no Type classes to be found. What is the Type class and what makes a TypeScript codebase have one?

Thank you!

@jpoly1219 jpoly1219 added the question Further information is requested label Jun 26, 2024
@jketema
Copy link
Contributor

jketema commented Jun 27, 2024

Hi @jpoly1219

Thanks for your question. Do you maybe have some example project from which you're missing type information? I expect the type information to be there if your database was created from a TypeScript codebase.

@jpoly1219
Copy link
Author

jpoly1219 commented Jun 30, 2024

Hi @jketema! Unfortunately I can't share code due to... reasons :) I will say that I have a tsconfig.json in the root directory, but I created a database in a subdirectory that gets ignored when compiling with tsc (I added the subdirectory to my excluded list). Does getType() rely on a d.ts file?

Otherwie, is there a setting that I need to change, or some dependencies that I need to install? If I know what allows for the getType() to work, then I could try fixing my codebase. If there are things I can do for you, please let me know!

I used the following commands to make my database:

codeql database create /path/to/subdirectory/mydb --source-root=/path/to/subdirectory --languge=javascript-typescript --overwrite

Thank you for your patience!

@jketema
Copy link
Contributor

jketema commented Jun 30, 2024

In that case please create a small example that demonstrates the problem.

@jpoly1219
Copy link
Author

jpoly1219 commented Jun 30, 2024

Ok, I made a small example. Check it out here: https://github.com/jpoly1219/codeql-gettype-example

After cloning and running npm install in the root, you should be able to run the query inside the codeql-custom-queries-javascript. The database is created using the command codeql database create subdir/exampledb --source-root=subdir --languge=javascript-typescript. I am using VSCode's CodeQL extension to run my query.

@jketema
Copy link
Contributor

jketema commented Jul 1, 2024

Thanks for the small example. So there needs to be a tsconfig.json file in your /path/to/subdirectory for getType() to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants