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
Allow tsconfig.json when input files are specified #27379
Comments
Could you provide a repro for a situation where tsconfig is ignored? |
|
Sure @andy-ms , but I mean, this is not even a bug. This behaviour is explicitly explained in the docs: When you do The lines of code are pretty easy to find I just can't understand why it's implemented this way. |
|
Probably because no one's implemented it -- could you explain what the use cases are? |
|
A pretty common practice is to have a pre-commit hook to compile only the staged files in your git project (It makes no sense to compile all the project). |
|
I have another use case for this. We have many projects that use typescript, and would like to reduce boilerplate and keep our typescript config in one place, so it can be uniformly applied across all our projects for consistency. At the moment, there isn't a way to do this, since you can't specify both a glob of files to check, and an external path to a This same goal is easily accomplished with TSLint, by using their |
|
related, but never considered #12958 |
|
I have a different use case that needs this as well. We have a pre-commit hook that does a quick type check ( Like @brapifra said here, #27379 (comment), it's written in the docs that this should be possible, but it clearly isn't. |
|
We have some questions for everyone in this thread Long story short, the real problem we see is that people make a and get garbage confusing errors because e.g. their However, we're not sure what Question 1, do we:
Question 2:
Question 3:
Thoughts? |
|
Just my two cents:
This use case seems problematic in general, since (AFAIK) TS needs to see your whole project for some things to work (e.g. |
|
Question 1. I would expect that we'll "Overwrite the files setting". Question 3. If we'll treat
Question 2. IMO I think there is cases when some modules pollute global scope and it might break the compilation (because not all modules require that modules with globals even if they use them), but I believe developers should import deps explicitly (via triple-slash directives or even |
@RyanCavanaugh So, we will not be able to pass path to the custom tsconfig via |
Typescript limitation -> microsoft/TypeScript#27379
|
Adding to the responses to the questions: Question 1
Question 2
Question 3
|
Typescript limitation -> microsoft/TypeScript#27379
|
We would find value in this for writing an arcanist Please find below the use-case and workaround in case you need itThe way arcanist external linters work is by specifying an
This way, .arclint {
"linters": {
"tsc": {
"type": "tsc",
// will call back linter just once, because we include just one file
// it could be any existing file in filesystem, it doesn't matter
"include": "/^linters\\/arc-tsclint\\/lint\\/linter\\/runner\\.js$/"
}
}
}linters/tsc/lint/linter/runner.js function main() {
// We don't end up using currentFile, refactor when 27379 is fixed
const [, , projectRoot, currentFile] = process.argv;
const { stderr, stdout, status } = spawnSync("tsc", ["--noEmit", "--jsx", "react"], {
cwd: projectRoot,
});
// Do arcanist-related stuff with stderr stdout and status
}Overall a similar use-case as the one @brapifra noted, and we would like not to be reliant on such a hack. |
|
One more use-case is serverless Lambda functions. It is convenient to have many related Lambda functions together in one project with common This not only allows to put less files into function's code, but (which is more important) to update only those functions that really uses changed code. Example Given following project structure: By executing following comands: I want to get following transpiled results that uses settings from Workaround Generate one-off child tsconfig files that overwrites echo "{\"extends\": \"./tsconfig.json\", \"include\": [\"src/handlers/a.ts\"] }" > tsconfig-only-handler-a.json
tsc --build tsconfig-only-handler-a.json |
**Problem** When we change code for only one of Lambda functions, we have to update all of them on `sam deploy` because every function contains all of JS files no matter whether they are being used by this particular function or not. **Solution** We can use the fact that when TypeScript compiler is given path to single file, it will only compile this file and all its dependencies. Given that every Lambda function has handler–an entry point–we can compile only this handler and will get only files required to run this given Lambda. To make TSC honor our configuration from `tsconfig.json` the hack with child tsconfig file is needed: https://stackoverflow.com/a/44748041 (see microsoft/TypeScript#27379 (comment) for details)
**Problem** When we change code for only one of Lambda functions, we have to update all of them on `sam deploy` because every function contains all of JS files no matter whether they are being used by this particular function or not. **Solution** We can use the fact that when TypeScript compiler is given path to single file, it will only compile this file and all its dependencies. Given that every Lambda function has handler–an entry point–we can compile only this handler and will get only files required to run this given Lambda. To make TSC honor our configuration from `tsconfig.json` the hack with child tsconfig file is needed: https://stackoverflow.com/a/44748041 (see microsoft/TypeScript#27379 (comment) for details)
|
As https://github.com/AkhmadBabaev mentioned here #27379 (comment) This worked for my project:
// lint-staged.config.js
module.exports = {
"*.{js,ts,tsx}": "eslint --cache --fix",
"**/*.ts?(x)": () => "tsc --noEmit",
}; |
|
I end up with |
npx esbuild ./config/*config.ts \
--tsconfig=./config/tsconfig.esm.json \
--outdir=./config-out \
--format=esm \
--out-extension:.js=.mjs \
--watch |
|
My use-case is that we have converted a messy JS codebase to TS, so there are thousands of type errors. We want to go through and clean them up gradually, over time. This means that we can't fail the build in CI for errors running It also means that running I would love to be able to run a command like |
|
My use-case has to do with Jest tests or In my opinion, if a project takes the effort to define a project-wide |
|
This issue has hundreds of @RyanCavanaugh's question appears to be settled. I speculate that a PR would be welcome that simply implemented the "overwrite |
This will use an ESM format config file for Lint-staged to allow use of functions. A function is needed for the Typescript CLI to follow the tsconfig (microsoft/TypeScript#27379 (comment)). The commands in an array will be executed one after another. This will prevent conflicts of a race condition.
|
It will be really nice if TypeScript team puts time on this issue. import * ns from "mod"And if the TS compiler finds files which import "ns", it automatically includes them in its compiling even though you don't want them to be type-checked. So to me, it sounds like TS will eventually look at extra files which might not be the ones you modified. We want the option to tell the compiler to check the specific files, about TS grammar only, Not checking every referencing file! |
This exists and is called |

brapifra commentedSep 26, 2018
I don't know why the
tsconfig.jsonis ignored even when the--projector-poption is specified.In my opinion, the right implementation should be:
--projector-poption: Ignore tsconfig.jsontsconfig.jsonwill be ignored when input files are specified.The text was updated successfully, but these errors were encountered: