-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Current version incorrectly analyzes @types/node #20
Comments
@gustavopch I didn't get a chance to look into it deeper. What I image could work is to check if they are supplying the path as part of the args and not include the empty array (or add it inside that array):
or else check if they have include already declared on their TS Config and use that? Not sure if this would work, have not tried it. |
I think this empty include introduces the issue where custom types are not able to include. src/App.tsx
src/types/window.d.ts
|
@IPWright83 The empty |
@IPWright83 Before, global declarations were taken into account because they were included by |
This is an idea to fix gustavopch#20. Instead of discarding all includes, which seems to discard required global `.d.ts` files, can we use the `typeRoots` a config may have setup instead? I don't think this quite hits the mark however: - Does everyone use `typeRoots` in this manner? I do not know. - Likely will not work for a monorepo with nested tsconfig as files are resolved to the root. - Often `typeRoots` will import a fair bit, this could still include a large % of your codebase. My `typeRoots` includes `node_modules/@types`–this may defeat the purpose gustavopch#18 set out to resolve.
While #18 solved one of my issues, I'll have to rollback to a previous version. I wondered if we could use the Edit: I also created a minimal example for the above PR: https://github.com/kylorhall/tsc-files-types-example |
@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 :) |
I believe I've sorted the issue for myself in a fairly large codebase (1m LOC, ~200k LOC being Typescript). Just came down to incorrect Full findings into: #22 (comment) I definitely don't think my idea of |
Is it possible to use a glob in includes to include all 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. |
Maybe a possibility is to have a command line argument to put in files/directories you want to include (so a custom types or declaration directory, or a specific .d.ts file) which you then populate the Or you could check to see if there's an 'tscFilesIncludes` section in the tsconfig.json file, and then populate the includes with that (or empty otherwise). This will let users then decide what files they're including absolutely needs to be processed by tsc-files, without it affecting normal tsc operation:
Though I'm not sure if this might affect any tooling checking for the correctness of tsconfig.json (as we're basically making a new key here) |
@deanolium I don't think a |
Using a glob could work, reading the Typescript docs. So maybe doing:
or
instead of the empty array could be a way to fix the issue without causing the kind of problems people are having. |
My understanding of typeRoots is that it solves a slightly different problem, which is for backwards compatibility with typings. The main issue is that if you leave typeRoots alone, then it will automatically import the types from all node_module directories in your tree. If you put any value into typeRoots, then it won't automatically add any of the node_module types - so you'll need to manually add these. Whilst it would technically work, it isn't really a setting people will be using for TypeScript that often. Also established packages which a lot of people use (for instance create-react-app with typescript) doesn't set this, so this behaviour will either require people modding their tsconfig. which they might not be knowledgable enough about doing, or convincing these large groups of devs to alter their config. Otherwise you'll essentially end up with people trying your tool, it failing in a way they don't quite understand, and then they just don't bother using it. Of course, any changes which requires users to alter their config (as I mentioned above) would itself be a pain point and require documentation. So I'm not really sure what the ideal solution is, bearing in mind that a lot of people using this tool probably know enough typescript to develop with it, but not enough to know all the settings in tsconfig and the implications of these changes. |
@deanolium It makes sense. On one hand, we can't simply include everything as it defeats the purpose of the tool (that's what happened before v1.1.3); on the other hand, we need to include global declarations. There's also the case where global declarations happen inside regular |
For the purposes of lint-staged I updated my entry to include my .d.ts files My package.json went from {
"lint-staged": {
"**/*.{ts,tsx}": [
"tsc-files --noEmit"
]
}
} To: {
"lint-staged": {
"**/*.{ts,tsx}": [
"tsc-files --noEmit src/defines.d.ts src/path/to/other.d.ts"
]
}
} This worked for my commits as the lint staged files will get added on after. |
this seems like the best solution to me. You really only need one file so long as imports whatever other globals you want. |
I discovered today that our large monorepo project that makes use of This can be overcome by creating a base tsconfig containing all your compiler settings, and a different tsconfig for specific use with // tsconfig.base.json
{
// All your typescript settings, WITHOUT your "include", "exclude" or "files" properties
} // tsconfig.ts-files.json
{
"extends": "./tsconfig.base.json",
"include": ["**/*.d.ts"]
} // tsconfig.json
{
"extends": "./tsconfig.base.json",
"include": ["**/*.ts"] // the normal 'include' array for your project
} 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 In my view, you probably should revert #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. |
@benwainwrightcinch Now I'm wondering if an |
@gustavopch I think that isn't a bad solution, I think if you do that you should definitely default to include declaration files as you suggest. |
I can't quite tell what the recommended approach is after reading this thread. For me
I've tried {
"compilerOptions": {
"typeRoots": ["./node_modules/@types", "./@types"]
}
} but no joy. Do I need to hunt down jest's |
@dr-skot Try to run |
@gustavopch I'm having success at the moment with "lint-staged": {
"**/*.ts?(x)": "tsc-files --noEmit --pretty next-env.d.ts node_modules/@types/jest/index.d.ts @types/millicast.d.ts"
} It doesn't work if I change It would be nice to consolidate that long // globals.d.ts
import 'next-env.d.ts'
import 'node_modules/@types/jest/index.d.ts'
import '@types/millicast.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. |
Props to this comment I fixed the issue on NextJS
|
If anyone finds a solution for CSS modules/vite environments, please let me know. I don't think I've seen anything in the comment thread here about it but my issue was closed as not-planned, so sounds like we're stuck waiting for tsc to add individual file support. |
@viveleroi |
Would be great to see a mention of this issue in the README! Had a similar issue with |
"lint-staged": {
"**/*.{ts,tsx}": "sh -c 'tsc-files --noEmit $(find ./src -name *.d.ts ! -path \"./src/.*/*\") $0 $@'"
}, i'm using this cmd to specify all d.ts |
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.
|
This seems effective but confusing for people to see in our package.json. Could something like this happen automatically behind the scenes in tsc-files? |
A possible less confusing version:
|
@gustavopch
In my project I have code like this:
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)The text was updated successfully, but these errors were encountered: