You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invoking TypeScript with --outDir src makes some source files invisible #60867
declare global {namespaceglobalThis{var__IS_CI__: boolean;}}export{};
🙁 Actual behavior
On TS 5.4, the command passes.
On TS 5.5 or newer, the command fails with the error:
src/test.spec.ts:5:12 - error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
5 globalThis.__IS_CI__ = true;
🙂 Expected behavior
I expect both commands to pass.
Additional information about the issue
I'm trying to migrate a large codebase off of Typescript 5.3, and this is the last blocker remaining.
--outDir src is passed to tsc via a Bazel build rule.
If {"outDir": "src"} is added to tsconfig.json, then typechecking will fail on both versions of TypeScript.
As I understand it, according to #58327, outDir causes source files to be excluded because otherwise, we'll overwrite the .d.ts files we're using as source files.
But if you don't specify outDir at all, your output directory will be the same as your source directory anyway, and somehow this won't be a problem. According to the TypeScript docs:
If [outDir is] not specified, .js files will be emitted in the same directory as the .ts files they were generated from.
Since we already have default behavior where the source and output directories are the same, why does specifyingoutDir cause such a different behavior?
Unless explicitly specified, exclude includes outDir as a default value. If you don't specify outDir then it has no value (since it has no default value) and is not part of exclude, that's why you see different behaviors.
Activity
MartinJohns commentedon Dec 29, 2024
See: https://www.typescriptlang.org/tsconfig/#exclude
Unless explicitly specified,
excludeincludesoutDiras a default value. If you don't specifyoutDirthen it has no value (since it has no default value) and is not part ofexclude, that's why you see different behaviors.jthemphill commentedon Dec 29, 2024
Ah, thank you! I may ask to add a link from
outDirtoexcludein the docs so that future mes are less confused🙂jthemphill commentedon Dec 29, 2024
This is the correct answer to my question!