tsc-files: Current version incorrectly analyzes @types/node
@gustavopch In my project I have code like this:
export const APP_ENVIRONMENT =
process.env.ENVIRONMENT
for which I include in my package JSON @types/node
In previous version (1.1.2) running tsc-file src/*.tsx --noEmit ran correctly without flagging ‘process’ as an issue (it understood the type).
In latest version: 1.1.3 I now get this:
I narrowed it down to this new line you added: (the include) when I comment that out, it works again and TS doesn’t flag process
as an issue (it sees my types/node)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 31 (10 by maintainers)
Commits related to this issue
- feat: add resolved typeRoots into the include This is an idea to fix https://github.com/gustavopch/tsc-files/issues/20. Instead of discarding all includes, which seems to discard required global `.d... — committed to kylorhall/tsc-files by kylorhall 3 years ago
- fix: set `include` to empty array so only specified files are processed Closes #18. — committed to gustavopch/tsc-files by IPWright83 3 years ago
For the purposes of lint-staged I updated my entry to include my .d.ts files
My package.json went from
To:
This worked for my commits as the lint staged files will get added on after. Maybe an ‘–global-files’ option that supports globing could be added to tsc-files to add be able to use globs in the list as lint staged does not expand them.
@benwainwrightcinch Now I’m wondering if an
--include
option should be added so you’d runtsc-files some-file.ts --include "**/*.d.ts"
. Perhaps even have**/*.d.ts
as the default value? I’d like to know what people following this issue think.this seems like the best solution to me. You really only need one file so long as imports whatever other globals you want.
Props to this comment I fixed the issue on NextJS
I discovered today that our large monorepo project that makes use of
tsc-files
to compile individual files on commit hooks suffered from the problem described in https://github.com/gustavopch/tsc-files/issues/5.This can be overcome by creating a base tsconfig containing all your compiler settings, and a different tsconfig for specific use with
ts-files
, so:This approach works well, and means you are still controlling the compilation source set using the config file rather than the command line as with the above solution. If I were to update the project to the latest version of
ts-files
, it would break us because you are overwriting theincludes
property.In my view, you probably should revert https://github.com/gustavopch/tsc-files/pull/18, as its an unnecessary solution that can be solved by configuring the compiler properly, and makes your tool harder to understand by those that expect the ‘include’ property to work as intended by the TypeScript team.
Is it possible to use a glob in includes to include all
*.d.ts
files, rather than having it be entirely blank? This is a breaking issue for me so I also had to rollback.Also, I noticed that 1.1.3 has broken your automated testing, so it really shouldn’t have been rolled into your main branch – it’s just bad code practice.
Note for anyone trying to import images into a TypeScript/React project: I had to create separate declaration files for each image type. Putting them into the same file didn’t work.
png.d.ts
:svg.d.ts
:i’m using this cmd to specify all d.ts
@gustavopch I’d suggest a warning which offers a recommended solution for projects which define “includes” in tsconfig. As we discussed in #5 it defeats the purpose of the project to include all files.
@gustavopch I don’t mind if you need to revert.
Honestly I know very little about TypeScript and just hit this rep after discovering terrible performance in our linting (>30s for a single file). I’m hoping to come back and think about this in some more depth soon 😃
While #18 solved one of my issues, I’ll have to rollback to a previous version.
I wondered if we could use the
compilerOptions.typeRoots
on-top of #18? This worked for my two use-cases, but I noted some caveats…idea in a PR: https://github.com/gustavopch/tsc-files/pull/22_Edit: I also created a minimal example for the above PR: https://github.com/kylorhall/tsc-files-types-example_
I think this empty include introduces the issue where custom types are not able to include. I have below running correctly in v1.1.2, but not in v1.1.3
% yarn tsc-files --noEmit src/App.tsx
src/App.tsx
src/types/window.d.ts