In tsconfig.json, the compilerOptions.types option seems to be ignored by ts-simple-ast.
ts-simple-ast API doesn't seem to get any type info from .d.ts files outside of the source root directory when using "types" option.
@osyrisrblx I'll look into this soon, but I feel like this should work. Could you show how ts-simple-ast is setup in your scenario?
@dsherret looks like if a .d.ts file is outside of the "rootDir", all of the defined types are picked up by ts-simple-ast as type "any".
Attempting to use Type.getSymbol(); returns undefined as well.
VSCode's built-in TypeScript seems to understand the types just fine which makes me think it's a ts-simple-ast bug.
@osyrisrblx how are you specifying the types compiler option in ts-simple-ast? I'll take a look soon.
@dsherret My tsconfig.json looks like this:
{
"compilerOptions": {
"strict": true,
"outDir": "out",
"rootDir": "src",
"baseUrl": "src",
"downlevelIteration": true,
"noLib": true,
"target": "ES5",
"types": [
"types",
]
}
}
where "types" is a folder inside the same directory as "src" and "out".
I've also tried replacing "types" with "types/", "types/*", and "types/**/*"
@osyrisrblx are you specifying to use the tsconfig.json?
@dsherret Yes, I supply a path to it when I create a Project object.
You can find the code here if it helps:
https://github.com/roblox-ts/roblox-ts/blob/master/src/class/Compiler.ts#L22
FWIW, I've been able to read properties like "baseUrl" from Project.getCompilerOptions().
@osyrisrblx ok thanks! Just making sure :)
You will want to use the "typeRoots" option and not "types". Read more here: https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types
There was a bug with "typeRoots" not working though. That's fixed now in 14.4.3.
@dsherret Unfortunately, it looks like I 馃帀'd prematurely. This bug is still occurring for me, and I made a small repro to demonstrate it with 14.4.3:
@osyrisrblx I was looking into this and the typeRoots option is not relevant in that situation. For example, when the typeRoots option is removed it will still work. I think perhaps tsc is being a bit generous in what it includes, but I'm not sure why. Perhaps it includes all .d.ts files regardless of the rootDir.
typeRoots is supposed to work on packages like @types packages (see here) and so it doesn't search for files in the directory specified.
For example, to see the true behaviour of typeRoots:
test-project. Then change typeRoots to "typeRoots": ["../typings"]. Run tsc and observe the compile error that it can't find Foo.typings create a sub folder called foo and move foo.d.ts into it. Rename foo.d.ts to index.d.ts. Run tsc and see it compiles now.If anything, perhaps this library should include all .d.ts files in the directory and sub directories of tsconfig.json, but I'm unsure if that's how tsc actually works. I'd need to look into it more.
@dsherret Is there currently a way with ts-simple-ast to include .d.ts which sit outside of the rootDir?
@osyrisrblx doing this should work: project.addExistingSourceFiles("typings/**/*.d.ts");
Most helpful comment
@osyrisrblx I was looking into this and the
typeRootsoption is not relevant in that situation. For example, when thetypeRootsoption is removed it will still work. I think perhapstscis being a bit generous in what it includes, but I'm not sure why. Perhaps it includes all.d.tsfiles regardless of therootDir.typeRootsis supposed to work on packages like@typespackages (see here) and so it doesn't search for files in the directory specified.For example, to see the true behaviour of
typeRoots:test-project. Then changetypeRootsto"typeRoots": ["../typings"]. Runtscand observe the compile error that it can't findFoo.typingscreate a sub folder calledfooand movefoo.d.tsinto it. Renamefoo.d.tstoindex.d.ts. Runtscand see it compiles now.If anything, perhaps this library should include all
.d.tsfiles in the directory and sub directories oftsconfig.json, but I'm unsure if that's howtscactually works. I'd need to look into it more.