question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`declarationDir` not used in extended tsconfig.json

See original GitHub issue

What happens and why it is wrong

When using a tsconfig.json that extends another tsconfig configuraiton file, the declarationDir is ignored unless "declaration": true is set in the extended tsconfig.json specified in the rollup.config

Expected behavior: The plugin respects "declaration": true in the base tsconfig file.

Environment

do not believe this to be relevant

Versions

  • typescript: 2.9.2
  • rollup: 0.63.4
  • rollup-plugin-typescript2: 0.16.1

rollup.config.js

// Lib
import path from 'path';
import * as pkg from './package.json';

// Plugins
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';

const moduleName = pkg.name;
const distDir = path.resolve(__dirname, '../../dist');

export default {
  input: path.resolve(__dirname, './src/index.ts'),
  output: {
    file: path.resolve(distDir, `${moduleName}.js`),
    format: 'cjs',
    sourcemap: true,
  },
  plugins: [
    resolve(),
    typescript({
      clean: true,
      include: [
        './src/**/*.ts',
      ],
      rollupCommonJSResolveHack: true,
      tsconfig: path.resolve(__dirname, './tsconfig.json'),
      useTsconfigDeclarationDir: true,
    }),
    commonjs(),
  ],
};

tsconfig.json

tsconfig.json

{
  "extends": "../tsconfig.base",
  "compilerOptions": {
    "declarationDir": "../../dist/types",
    "outDir": "../../dist",
    "rootDir": "./src"
  },
  "exclude": [
    "test"
  ]
}

tsconfig.base.json

{
  "formatCodeOptions": {
    "indentSize": 2,
    "tabSize": 2
  },
  "compilerOptions": {
    "target": "es5",
    "module": "es2015",
    "allowJs": false,
    "checkJs": false,
    "declaration": true,
    "declarationMap": true,
    "removeComments": false,
    "downlevelIteration": true,
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": true,
    "moduleResolution": "node",
    "esModuleInterop": true
  }
}

package.json

plugin output with verbosity 3

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SteveByerlycommented, Jul 30, 2018

great, thanks for the update. i’ll do my best to get something going in the next week.

fortunately this isn’t blocking anything - workaround is just to set the declaration in the extended tsconfig.

1reaction
ezolenkocommented, Jul 30, 2018

Looks like this is because rpt2 resets declarationDir if it doesn’t detect declaration in raw tsconfig (before ts had a chance to parse it and merge things from tsconfig.base).

PR is always welcome! Best way to fix it would be changing getOptionsOverrides to use parsed tsconfig (returned by tsModule.parseJsonConfigFileContent) and then apply generated overrides and parse tsconfig again before returning it from parseTsConfig. This way we’ll be most consistent with what tsc does on its own.

Read more comments on GitHub >

github_iconTop Results From Across the Web

declarationDir not used in extended tsconfig.json - Bountysource
What happens and why it is wrong. When using a tsconfig.json that extends another tsconfig configuraiton file, the declarationDir is ignored ...
Read more >
declarationDir - TSConfig Option - TypeScript
TSConfig. declarationDir ... An overview of building a TypeScript web app. TSConfig Options. All the configuration options for a project.
Read more >
How do I set `compilerOptions.declarationDir` to be a relative ...
my-package/tsconfig.json { "compilerOptions": { "declarationDir": "./dist/stypes" } }. Then in my package, I use: { "extends": "my-package" }.
Read more >
why declaration can not be used together with ...
In other words, isolatedModules does not provide enough type information for the creation of complete and ... tsconfig-for-declarations.json
Read more >
aspect-build/rules_ts
However, if your tsconfig.json uses the extends feature from TypeScript, ... Gathered NpmPackageStoreInfo providers are used downstream as direct ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found