Skip to content
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

Does not work when tsconfig uses "include" #9

Closed
jamesopti opened this issue Jun 10, 2020 · 8 comments
Closed

Does not work when tsconfig uses "include" #9

jamesopti opened this issue Jun 10, 2020 · 8 comments

Comments

@jamesopti
Copy link

jamesopti commented Jun 10, 2020

I'm trying to use this tool to generate a type definition file for a single entrypoint (there are many in my codebase that all share a single tsconfig.json).

Desired usage:

npx tsc-files src/bundles/app1/index.ts

TSConfig:

{
  "compilerOptions": {
    "baseUrl": "src",
    "target": "es2015",
    "module": "es2015",
    "jsx": "react",
    "declaration": true,
    "emitDeclarationOnly": true,
    "experimentalDecorators": true,
    "outFile": "types/index",
    "strict": true,
    "noImplicitAny": true,
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*", "index.d.ts"],  <--- I WANT TO IGNORE THIS!
  "exclude": ["dist", "docs", "node_modules", "tmp"]
}
vinnymac added a commit to vinnymac/tsc-files that referenced this issue Jun 11, 2020
This adds support for the use case specified in gustavopch#9
@vinnymac vinnymac mentioned this issue Jun 11, 2020
@gustavopch
Copy link
Owner

Hey @jamesopti. I'm not sure if tsc-files should be responsible for that. I mean, people may need to exclude arbitrary keys from their tsconfig.json files.

This tool is meant to be a tiny wrapper on top of the original tsc CLI with the sole purpose of providing a workaround for microsoft/TypeScript#27379 while they don't fix that behavior in tsc itself, so adding extra flags or parameters is something I want to avoid as much as possible.

But I believe there's a much simpler way to solve your use case. You could have a tsconfig.base.json which would contain everything except the include key:

{
  "compilerOptions": {
    "baseUrl": "src",
    "target": "es2015",
    "module": "es2015",
    "jsx": "react",
    "declaration": true,
    "emitDeclarationOnly": true,
    "experimentalDecorators": true,
    "outFile": "types/index",
    "strict": true,
    "noImplicitAny": true,
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  },
  "exclude": ["dist", "docs", "node_modules", "tmp"]
}

So you'd call tsc-files with the -p tsconfig.base.json parameter. Then, you'd have tsconfig.json:

{
  "extends": "./tsconfig.base.json",
  "include": ["src/**/*", "index.d.ts"]
}

@sjungwirth
Copy link

same issue I had in #5

@KATT
Copy link

KATT commented Oct 8, 2021

Hey @gustavopch - just came across this project whilst researching an issue for a situation I'm in.

I'm working on a fairly large TypeScript-based project where people have been ignoring errors for a long time - the include-array has a bunch of stuff that has type errors. I would personally love #10 to make it in. Would this be possible?

Thanks.

@zomars
Copy link

zomars commented Oct 15, 2021

We might need to make our own fork @KATT

@gustavopch
Copy link
Owner

It's not clear to me if there's anything wrong with the rationale and the solution that I provided in #9 (comment).

@zomars
Copy link

zomars commented Oct 16, 2021

We just don't want to modify the tsconfig to accommodate to this tool. Nothing wrong really.

@gustavopch
Copy link
Owner

@zomars Thanks for your answer. My concern is that someone may need to remove exclude, then someone else may need to remove some items from include while keeping others, and so on. That is, it doesn't seem like simply adding a flag to remove include will solve all use cases. Adding that flag would just be what we call a gambiarra in Brazil — the opposite of an elegant solution. The only solution that I can see that's able to conform to all possible use cases without bloating tsc-files and transforming it into a config editor is by using a separate config file.

@gustavopch
Copy link
Owner

OK, now I actually understand the issue.

When you run tsc-files src/foo.ts, you want to process src/foo.ts alone, but if you have "include": ["src"] in your tsconfig.json, it processes everything in the src folder, not just src/foo.ts. That behavior is a bug because it defeats the whole purpose of this tool — and so it should neither need a flag nor be extensible to other config properties.

I've just merged #18 which solves it in a very simple way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants