ds300 / react-native-typescript-transformer

Seamlessly use TypeScript with React Native
MIT License
657 stars 55 forks source link

feature: Support tsconfig extension JSON - fixes #74 #97

Closed alechill closed 5 years ago

alechill commented 5 years ago

The problem:

Within a monorepo, we use extension of TS config via local files and a sharable node module. This allows the editor and tsc to type-check using project references etc, and for config to be kept consistent. The same mechanism for config extension is not supported by Metro (via babel), nor by react-native-typescript-transformer, so React Native sub projects cannot be compiled in the same manner at the moment.

Appreciate that this project is being superseded by the babel TS support, but as Metro only just introduced that, we and many others are still compiling via react-native-typescript-transformer. Therefore decided to fix it here first, to buy more time (as a fix will be needed for config extension in babel too)

Solution supports:

Examples

// absolute file
{
    "extends": "/usr/local/my-config.json",
    "compilerOptions": {
    }
}
// relative file
{
    "extends": "../my-config.json",
    "compilerOptions": {
    }
}
// node module path (resolves to the file referenced as "main" in the package)
{
    "extends": "ts-config",
    "compilerOptions": {
    }
}
// scoped node module path (resolves to the file referenced as "main" in the package)
{
    "extends": "@scope/ts-config",
    "compilerOptions": {
    }
}
// node module sub path (resolves to base.json in the package) 
{
    "extends": "@scope/ts-config/base",
    "compilerOptions": {
    }
}
ds300 commented 5 years ago

Published in v1.2.13 :tada: