Option to respect closest tsconfig.json of imported files #37853
Labels
Suggestion
An idea for TypeScript
Too Complex
An issue which adding support for may be too complex for the value it adds
Search Terms
use nearest tsconfig.json for imported packages
Suggestion
When importing source files which have source that is expected to be compiled using a different tsconfig.json, the compiler will throw errors if the imported source has code which conflicts with the compiler options which the compiler was initialized with.
eg:
consumer
importstarget
.consumer
hasstrict: true
while thetarget
hasstrict: false
Add an option to the
compilerOptions
such asuseNearestTSConfigInImports: boolean
.This will help to avoid the necessity of the complex build systems, symlinks and project structures we see in modern multi-package TypeScript projects.
Use Cases
When working with projects that contain multiple services, it's beneficial to abstract and share dependencies which are used across the multiple consumers.
While TypeScript source can be imported from folders arbitrarily, this assumes the source conforms to the configuration in the compilerOptions of the current context.
As soon as the source needs to be shared between consumers developers must:
Examples where that might be the case:
strict: true
yetstrictBindCallApply
)This complexity is introduced pretty quickly in projects and would be easily mitigated by allowing the TypeScript compiler the capacity to use the nearest tsconfig as the source of truth for the files nested in the folders below it.
It enable projects written in TypeScript with no consideration of JavaScript until the service was to be published. This results in very clean and easy to traverse repositories.
Something like this is currently possible using comments, eg: adding
/** @jsx y */
will override the jsx pragma in the current file.Examples
Here I have an example repository which breaks, but demonstrates the feature proposal.
https://github.com/alshdavid-sandbox/respect-nested-ts-config
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: