Skip to content

Invoking TypeScript with --outDir src makes some source files invisible #60867

Closed

Description

🔎 Search Terms

outDir globalThis declarations exclude include not found error

TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature

🕗 Version & Regression Information

⏯ Playground Link

https://github.com/jthemphill/ts-5.5-repro

💻 Code

Run with tsc --outDir src.

tsconfig.json:

{
  "compilerOptions": {
    "noEmit": true,
    "noImplicitAny": true
  },
  "files": ["src/test.spec.ts"],
  "include": ["./src/**/*"]
}

src/test.spec.ts:

globalThis.__IS_CI__ = true;

common.ts:

declare global {
  namespace globalThis {
    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 specifying outDir cause such a different behavior?

Activity

  1. MartinJohns commented on Dec 29, 2024

    @MartinJohns
    Contributor

    See: https://www.typescriptlang.org/tsconfig/#exclude

    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.

  2. jthemphill commented on Dec 29, 2024

    @jthemphill
    Author

    Ah, thank you! I may ask to add a link from outDir to exclude in the docs so that future mes are less confused🙂

  3. jthemphill commented on Dec 29, 2024

    @jthemphill
    Author

    This is the correct answer to my question!

  4. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions