Repository navigation
skipLibCheck: true is ignored when package's types field points to a .ts file (not a .d.ts declaration file) #41883
Description
Activity
RyanCavanaugh commented
on Dec 8, 2020 MemberMore actionsskipLibCheckcauses the "check each top-level statement or declaration" step to not occur for.d.tsfiles.It has no other effect. It does nothing in
.tsfiles, and is not a guarantee that you won't encounter errors in.d.tsfiles whose declarations get examined as a part of their resolution.I think one would intuitively expect no errors from inside
node_modules(unless it is critical, like invalid syntax?) whenskipLibCheckistrue, because ultimately the dependency code is plain JavaScript (or will end up as plain JavaScript).For example, the Webpack build in the consumer app works fine, it pulls in the non-
.tsfiles fromdist/, and the app works fine.The types in the
lumepackage work just fine when that repo is cloned and build withtsc. The errors I see are in another project that just installedlumeand presumably uses a different version oftsc. Intuition here expects the code to be fine.How do we assert to
tscthat everything is fine and to strictly ignore those type errors in node_modules?Reacted by Lucas Basquerotto, Clinton Blackburn, Aaron Hickman, pawlarius, Homa Wong, Adam Averay, ducttapedev, Kristijan Korać, Sean Blonien, Bhavit Sharma and 11 moreRyanCavanaugh commented
on Dec 8, 2020 MemberMore actionsThere isn't a setting that would cause TypeScript to not issue an error in a
.tsfileThis circles back to (some issues in) #35822, because we can not consume mixin classes from a package unless the package's
typesfield points to.tsfiles (because the package author can not output declaration files if they use mixin classes).Without
typespointing to.tsfiles, making mixins can go like follows.From #17744 (comment) (Justin Fagnani (@justinfagnani)):
The workarounds we've had to do to satisfy the compiler are pretty onerous. We've created a fake class outside of the mixin and cast the mixin function to return an intersection of the argument and that class. Static require another fake class. Then we need to get our build system to remove the fake class. I'm not sure this approach solved every problem yet.
- addedWorking as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
on Dec 9, 2020 DanielRosenwasser commented
on Dec 9, 2020 MemberMore actionsWe are interested in making
.d.tsfile generation less of a hassle, but patchingskipLibCheckfor the use-case of shipping.tsfiles to get around the issues described is not the direction we want to take.Reacted by Gerrit Birkeland and Jacek NowackiReacted by Scott Blevins, Michael Zhuang (Hao) , Liam Daley, norrisduncan, Zack, itsHel, christopher-helling, Matthew Dean, Felipe González Alarcón and Michal Srbtypescript-bot commented
on Dec 11, 2020 ContributorMore actionsThis issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
Reacted by Scott Blevins, Jamie Kerber, Chris, Arseni Shmialiou, Juan Ramón, Liam Daley, Jake Harris, Christian Toney, ducttapedev, Emil Einarsen and 35 moreDaniel Rosenwasser (@DanielRosenwasser) Is it possible to make TypeScript skip type-checking source files of libraries (i.e. when their package.json
typesfield points to source instead of declaration files)?This would make shipping neat features possible, that are otherwise currently not allowed when declaration output is turned on.
As an example, all the issues listed in #35822 would be solvable by simply recommending people in those cases to point their
typesfields to their source entrypoints.The alternatives are to wait an unknown number of years for a solution, or to abandon the cool features. Adding such a solution would be a very simple unblocker for those nice use cases.
Of course, if declaration output could be fixed, that'd be preferable, but the pace at which that is happening is very slow, and the alternative suggested solution seems to be a lot easier to unblock many people from using cool patterns.
DanielRosenwasser commented
on Apr 19, 2021 MemberMore actionsIf the community starts shipping full source in place of
.d.tsfiles, my expectation is that users would start running into scalability concerns in building (and this is actually much of the motivation for project references). It would also potentially exacerbate issues where.d.tsemit would otherwise be stable when adopting new non-declaration ECMAScript features.This issue, together with #38538, is what we're seeing as well.
The core seems to be that that TypeScript checks imported
.tsfiles regardless of whether they are source files or external dependencies, and options likeinclude,excludeorskipLibCheckdon't have any effect on this (rightfully so but that doesn't make the issue go away 😄).We think that TypeScript just crawls
imports inside files that matchinclude/excludeand that it then runs a typecheck on everything it finds:.tsfiles are checked unconditionally.d.tsfiles are checked if not disabled viaskipLibCheck
The first point is a problem – we don't want to see errors from
node_modulesor generally from.tsfiles that are not source files of the current project.I acknowledge that
skipLibCheckmight not be possible to amend (though intuitively,node_modules/some-plain-ts-libraryis a library) but there should be some way to prevent it. There is currently no workaround as far as I know.
Some context: besides the use case reported by the OP (
"types"pointing to.ts), there's another one.Modern frameworks like Next.js, Gatsby, CRA and others process TypeScript "natively" so it's actually better not to transpile
.tsand leave this job on webpack / Babel / esbuild / whatever the transpilation pipeline that framework uses. This leads to a new world where.js+.d.tsfiles don't exist on the disk – for example, in our Next.js project, we never run full transpilation, that's up to thenext dev/next buildto produce some.jsbundles.We're using TypeScript as a "linter" only, i.e.,
tsc --noEmit.Reacted by Jonathan Raoult, Finn Merlett, Scott Blevins, Christopher David, Michael Zhuang (Hao) , Juan Ramón, Tanel Koha, Jake Harris, 柏, Sean Blonien and 16 moreReacted by geoshakRyanCavanaugh commented
on May 3, 2021 MemberMore actionsThe core seems to be that that TypeScript checks imported .ts files regardless of whether they are source files or external dependencies
The first point is a problem – we don't want to see errors from node_modules or generally from .ts files that are not source files of the current project.
This is indistinguishable from an intentional configuration. We'd need some more intentional way for you to specify what's "yours" and "not yours"
Ryan Cavanaugh (@RyanCavanaugh) I agree.
I intuitively thought that
excludewould do this (it seems to be a common try by people hitting this issue) but I now understand that it behaves differently so that's not a way.I'd say that "my code" is everything under the current folder (where
tsconfig.jsonis) minusnode_modules. So<project>/../lib/*.tsis not my source code, neither is<project>/node_modules/abc/index.ts.I imagine it would still be possible to explicitly include those if one wants, like this:
{ "include": "node_modules/abc/*.ts" }Do you see any glaring holes in this or could it work?
Reacted by Nate-Wilkins and Márton PolgárActually, while I assumed that
excludecannot be used by this, is it really that impossible? Would it break some important workflows ifexcludestarted excluding errors from paths underexclude?(I think I understand what
excludecurrently does and I know I'm suggesting a change in behavior, I just wonder whether projects realistically list paths underexcludeyet expect to see errors from those.)I faced this same issue past friday. It's even weird because the library we used had a few TS rules off in its
package.json, but at the moment it wasimportedin the project, it ignored the library config and used our main project config, which obviously will fail.For now, the only workaround we found was to replace the
importfor that lib with arequire.Reacted by Anton Baranoff, William , Paras Sanghavi, sushil2501 and ekleninReacted by Douglas GubertTangentially related but Deno 1.17 now supports
--no-check=remote:The
--no-check=remoteoption was added to help with this. When this flag is passed, the program will be type checked as a whole, but any diagnostics that are coming from a remote module will be discarded. If there are no local diagnostics, your program will run.Feels similar in spirit to this issue.
Reacted by ekleninThe problem also occurs when the
typesfield inpackage.jsonrefers to a.d.tsfile and there is a.d.ts.mappresent which links to the.tssource.Typescript tries to recompile the source in that case, which seems wrong.
Reacted by Jonathan O'Donnell, Homa Wong and Nikolai IakovlevJust hit this and have no idea how to resolve, no changes to any tsconfig files or updates to typescript or the problematic library but the build is throwing this:
../node_modules/native-base/src/hooks/useContrastText.ts:43:52 Type error: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'. 41 | bgThemeColorVariant && 42 | themeColorsThresholdShades[bgThemeColorVariant] > 43 | ? getContrastThemeColor(bgThemeColorVariant, bgShade) | ^ 44 | : getAccessibleContrastColor( 45 | contrastThreshold, 46 | trueDarkText, info - Checking validity of types .task: Failed to run task "web-build": exit status 1What's the advised way to go about this? Surely it can't be changing all imports to requires that would result a huge diff and seems backwards. This is working fine on another branch and it seems to only be this file that's failing.
And yes
"skipLibCheck": true,is there and excludenode_modulesis there, has been working fine for months.Reacted by Zac Butko, Saad Bin Waheed, Sahil Agarwal, Richard, Philippe Poulard, David Schkalee, Corbin Crutchley, Sebastian Fredriksson Bernholtz, htbkoo, Adam Haglund and 2 moreI have the same issue with
"typescript": "^4.7.4"$ npx tsc --skipLibCheck true node_modules/react-dropzone-uploader/dist/Dropzone.tsx:504:44 - error TS2571: Object is of type 'unknown'. 504 console.error('Error Upload Params', e.stack) ~ Found 1 error in node_modules/react-dropzone-uploader/dist/Dropzone.tsx:504It was working with previous version of typescript (4.5)
Reacted by Anton Novikov, Sebastian Hewelt, eklenin and Alexandre AnícioIf you're using webpack with the
ForkTsCheckerWebpackPlugin, I found a pretty weird solution which makes the error disappear:new ForkTsCheckerWebpackPlugin({ ..., issue: { include: [ { file: '**/*' } ] } })
So just including everything makes it work for me again.
Reacted by mwalkerrI faced this same issue past friday. It's even weird because the library we used had a few TS rules off in its
package.json, but at the moment it wasimportedin the project, it ignored the library config and used our main project config, which obviously will fail.For now, the only workaround we found was to replace the
importfor that lib with arequire.I changed "module" in "compilerOptions" to be "ES2020" from "commonjs" and it seemed to resolve this bug for me.! excluding 'node_modules', setting skipLibCheck to true, and setting types=[] did not work for me, but this did.
David Schkalee (@misantronic) That did it for me, thank you very much for dropping by with that :). How did you end up trying that setting?
That did it for me, thank you very much for dropping by with that :). How did you end up trying that setting?
tbh, I don‘t remember 😅 I might have looked into the source and found how it would work.
So what is the status here? I understand that all of the existing settings are working as intended (ie: include, exclude, skipLibCheck).
But for the increasingly common use case of using
tsc --no-emitfor linting purposes (rather than compiling), there doesn't appear to be any workable solution. Should a new issue be made for that? Or is this considered a "wont-fix"?Reacted by Alexey Iskhakov, Eliott C., eklenin, Sebastian Fredriksson Bernholtz, Jon Eubank, schengit, Adam Haglund, Alex Montague, Dmitry Koplyarov, Anatoly Belonog and 6 moreReacted by BartusZak and Felipe González AlarcónFor anyone finding this in 2023, using typescript Version
5.2.2or newer appears to do the right thing when specifyingskipLibCheckin thepackage.json.For anyone finding this in 2023, using typescript Version
5.2.2or newer appears to do the right thing when specifyingskipLibCheckin thepackage.json.Alex Daigle (@deepio) I'm still observing this with 5.2.2 and skipLibCheck - did you tweak anything else?
RyanCavanaugh commented
on Oct 11, 2023 MemberMore actionsNothing material about
skipLibCheckhas changed in 5.2.skipLibCheckmeans that.d.tsfiles aren't "checked" (this is a term of art that means, for each source element, that element is explicitly validated, possibly producing errors; it doesn't mean that an error cannot occur in that file)There is no setting that causes
.tsfiles to not be checked.If you have a
.tsfile in your project where that.tsfile isn't under your control (e.g. it's coming fromnode_modulesin someone else's package), that's a configuration error, either on your part or the package author's. Package authors should be configuring their packages such that inbound references resolve to.d.tsfiles.There is no setting for ignoring this misconfiguration, since if you're in this state, important compiler settings (
exactOptionalPropertyTypes,noUncheckedIndexedAccess, etc) change the meaning of.tscode in ways that will produce incorrect results. The only fix is to fix the misconfiguration.- locked as resolved and limited conversation to collaborators
on Oct 11, 2023
TypeScript Version: 3.9.7
Search Terms:
skipLibCheck is ignored
skipLibCheck not working
Code
N/A
Expected behavior:
TypeScript should ignore type errors in node_modules (or skip reporting them? I'm not sure exactly what
skipLibCheckdoes).Actual behavior:
When
skipLibCheckis set totrue, TS will still have type errors in packages innode_modules. It seems that this is the case if a package'stypesfield in the package'stsconfig.jsonfile points to a.tsfile instead of a.d.tsfile.For example, in my project that consumes the
lumepackage, there are type errors like these:As you can see the path in the errors are in
node_modules. Thelumepackage'stypesfield points to itssrc/index.tsfile, and hence all the types in that package are based on.tsfiles instead of.d.tsfiles.Playground Link:
N/A
Maybe I misunderstand what
skipLibCheckdoes. What should it do exactly?