Skip to content

Broken (unrelated) ambient types in the user's node_modules can cause --emit-tsd builds to fail #22996

Closed

Description

@jedrichards

The tsc invocation here seems sensitive to unrelated broken types present in the users node_modules/@types folder.

I believe TypeScript checks types in node_modules/@types, and it's not uncommon for these to be broken in some way (duplicate identifiers when multiple versions of the same package are present in a monorepo, 3rd party type incompatibilities and so on).

The issue is solved by passing the --skipLibCheck flag to tsc. Or alternatively, perhaps invoking tsc in some temporary cwd that is not the user's project, where we're not going to trigger random errors from npm dependencies.

Activity

  1. added
    TypeScript
    on Nov 25, 2024
  2. brendandahl commented on Nov 25, 2024

    @brendandahl
    Collaborator

    With --skipLibCheck are there any other issues that can come up from running tsc in the CWD?

  3. jedrichards commented on Nov 26, 2024

    @jedrichards
    Author

    @brendandahl From what I understand, --skipLibCheck is something you might want to turn on when you want to validate that everything is working also with respect to .d.ts types that might be coming in from dependencies (from node_modules/@types/...) that you want to be compatible with - for example, prior to publishing a TypeScript libray to npm or something.

    So I think, it's sensible to toggle it off when we're just typechecking our own code, especially if that code is self-contained (i.e. it doesn't rely on any 3rd party ambient types itself).

    With --skipLibCheck any broken types from node_modules that are actually referenced, are typed as any, but non-broken ones are still properly typed. But that may be a moot point anyway, since in this case, I do not think js_doc_file uses any 3rd party types?

    It seems common practice to use the flag:

  4. added 2 commits that reference this issue on Nov 26, 2024
    3ac2e0c
    5b5cd86
  5. added a commit that references this issue on Dec 4, 2024
    d833c39
  6. added a commit that references this issue on Dec 18, 2024
    2337a41
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

    TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions