question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`skipLibCheck: false` does not output diagnostics for ambient types

See original GitHub issue

What happens and why it is wrong

tsconfig.compilerOptions.skipLibCheck is by default false, but will always be forced to true when using rpts2.

This isn’t documented in the README “Some compiler options are forced” so I’m not sure why this is the case or if this is intentional. I couldn’t find any code references or issues about this.

Related to https://github.com/jaredpalmer/tsdx/issues/529#issuecomment-593737935

Environment

TSDX@0.12.3

Versions

  • typescript: 3.7.3
  • rollup: 1.27.8
  • rollup-plugin-typescript2: 0.25.3

rollup.config.js

TSDX Rollup

tsconfig.json

package.json

plugin output with verbosity 3

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ezolenkocommented, Mar 12, 2020

Plugin’s exclude is for avoiding transpiling those files (no js would be generated by transpiling d.ts), also typescript files shouldn’t be importing type files, I think they are supposed to be magically found by tsc, but never imported.

Also rollup does tree shaking and some files might be never imported. You should see evidence of that in verbose output – do a build and see if any source files that use affected type file are even transpiled.

Also check if cache is potentially hiding it, do a build with clean: true and see if you see expected error. rpt2 tries to build full import tree when tracking which files should be rebuilt, but ephemeral things like d.ts files might slip through the cracks.

Usually typescript will find all ambient type files and rpt2 will list them at the start of the build and invalidate cache if they changed.

0reactions
agilgur5commented, Jun 28, 2022

So now that I know this codebase really well, I’m pretty sure that the problem is that rpt2 doesn’t output diagnostics for any ambient types. I’ve renamed the issue as such. We basically only output diagnostics in the transform hook, so only for files that are being compiled to JS and not treeshaken by Rollup (i.e. #298)

So while the skipLibCheck setting may impact TS’s actual program analysis, no diagnostics will be output regardless of how it’s set, because we don’t process ambient typings.

Basically, to properly follow TS behavior, we’d want to emit diagnostics for all ambient typings as well when skipLibCheck: false. Possibly in checkAmbientTypes.

That would greatly decrease performance, so I might suggest to add a plugin option that disables this by default. That being said, skipLibCheck is recommended to be false by the TS team anyway:

Definitely low priority if it would be disabled by default; that would just be a tsc parity thing then.

That being said, I believe when I originally made this issue I was actually authoring a declaration file and it wasn’t checked (or something? would’ve been great if I made a repro 😅 ). This not being type-checked because of the default exclude is probably accurate in that case and that use-case wouldn’t be so low priority.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TSConfig Reference - Docs on every TSConfig option
Compiler Options. These options make up the bulk of TypeScript's configuration and it covers how the language should work. Type Checking; Modules; Emit ......
Read more >
Understanding TypeScript's skipLibCheck Once and For All
Understand how to use Typescript's skipLibCheck to skip checking of declaration files in this blog by Testim Developer Omri Lavi.
Read more >
Microsoft/TypeScript - Gitter
Do we generally want skipLibCheck as false ? ... How do I import a type in a .d.ts file, to use it in...
Read more >
Usage of the TypeScript compiler argument 'skipLibCheck'
Since declarations in one file can affect type checking in other files, some errors may not be detected when --skipLibCheck is specified. For ......
Read more >
TypeScript Cheatsheet, Common Errors, and More
If using an ambient declaration file only for types interface Window ... You'll get kind of a cryptic error like Type 'string' is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found