Skip to content

Feature Request: allow exclusion of node_modules when skipLibCheck is false #30511

Open
@bensaufley

Description

@bensaufley

Search Terms

skipLibCheck node_modules, skipLibCheck

All I've found is this lonely SO post. As that user notes, there are a lot of posts around Angular and excluding node_modules from typechecking on one dimension or another, but they all end up suggesting turning on skipLibCheck.

Suggestion

Allow the exclusion of files in node_modules (regardless of their inclusion in the Project) from lib checking when skipLibCheck is set to false.

Use Cases

I want to be able to typecheck my own .d.ts files without being responsible for all of the types my dependencies import. My local configuration is strict and it may be that the types provided in my packages were not intended strictly, or other configurations in my local JSON run up against the way other packages have written theirs.

I am assuming the counterargument is that it's all-or-nothing, but then why do .ts files that rely on .d.ts files typecheck fine when my .d.ts files are not typechecked? Can't that behavior be applied to definitions in node_modules?

Examples

Not sure how to show an example here. I would like to be able to run tsc --noEmit on my codebase and get errors for my own definitions files without having a bunch of noise from unfixable errors in node_modules/@types etc.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
    If implemented as some additional flag?
    This wouldn't change the runtime behavior of existing JavaScript code
    This could be implemented without emitting different JS based on the types of the expressions
    This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
    This feature would agree with the rest of TypeScript's Design Goals.
    I think so?

Activity

changed the title [-]Allow exclusion of node_modules from skipLibCheck[/-] [+]Feature Request: allow exclusion of node_modules from skipLibCheck[/+] on Mar 20, 2019
RyanCavanaugh

RyanCavanaugh commented on Mar 26, 2019

@RyanCavanaugh
Member

It sounds like you're asking for the opposite - a mode for skipLibCheck that says only skip checking of .d.ts files from node_modules?

bensaufley

bensaufley commented on Mar 26, 2019

@bensaufley
Author

You're right, that wasn't the right phrasing (I was thinking of skipLibCheck: false—excluded from enabled libCheck).

changed the title [-]Feature Request: allow exclusion of node_modules from skipLibCheck[/-] [+]Feature Request: allow exclusion of node_modules when skipLibCheck is false[/+] on Mar 26, 2019
bensaufley

bensaufley commented on Jul 5, 2019

@bensaufley
Author

FWIW I think this ongoing issue is my biggest use case for this flag: Styled-Components automatically includes React-Native types, which duplicate Node types, so if you use Styled-Components and Node, you must skipLibCheck because of a long-standing problem that you have no power to fix

jasonkuhrt

jasonkuhrt commented on Sep 30, 2019

@jasonkuhrt

Another use-case for this feature comes from nexus.

Nexus has a novel "typegen" feature wherein based on user code a TS types file is generated and via interface-merging is able to imbue static guarantees on otherwise dynamic app code.

We are currently working on making the default disk location for this typegen be node_modules/@types/whatever/index.d.ts. This allows nexus to provide the typegen DX without any config demands upon the user.

Now, the motivation, for us, for this TS issue, is that nexus typegen would become weaker in the face of skipLibCheck. Advanced users can configure typegen output, but their getting it wrong while skipLibCheck: true would make it silently fail. This TS feature would help maintain our users' confidence in nexus typegen even in situations where they need to skipLibCheck for just one or two libs in their project.

Hope that makes sense :)

zanona

zanona commented on Nov 27, 2020

@zanona

I completely agree with the author.

I am not sure if it would make sense or whether this has any negative effect, but the only way I could make sure my declaration files didn't have any errors, was to rename all .d.ts to .ts, while keeping skipLibCheck=true.

I faced many situations where I did have errors on my .d.ts files to only figure it out once those were then checked by tsc after being renamed.

I might be missing something though.

cbdeveloper

cbdeveloper commented on Jan 6, 2021

@cbdeveloper

My use case for this is also related to the styled-components and @types/react-native issue. I'm getting 40 errors.

It does not harm my code, so I would like to ignore all those errors by setting --skipLibChecks: true, while still checking and getting errors for my own .d.ts files inside my src folder.

Any updates on this?

45 remaining items

Loading
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

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @zanona@thorn0@jasonkuhrt@bensaufley@DanKaplanSES

        Issue actions

          Feature Request: allow exclusion of node_modules when skipLibCheck is false · Issue #30511 · microsoft/TypeScript