Error `TS5052` when `declarationDir` is set, but `declaration: false` override
See original GitHub issueWhat happens and why it is wrong
Typescript compile option doesn’t allow set declaration: false
and declarationDir
at same time.
options error TS5052 Option 'declarationDir' cannot be specified without specifying option 'declaration'.
But according to https://github.com/Microsoft/TypeScript/issues/14184, setting with declarationDir: null
and declaration: false
is able to cancel emitting type files.
Unfortunately, after setting override declarationDir: null
, declaration: false
and useTsconfigDeclarationDir:false
, in lvl 3 verbosity, terminal reports that declarationDir in parsed tsconfig is current project path. The expected declarationDir
should be null
.
Environment
Versions
- typescript: 2.6.2
- rollup: 0.55.1
- rollup-plugin-typescript2: 0.10.0
rollup.config.js
import typescript from 'rollup-plugin-typescript2'
import camelCase from 'camel-case'
const pkg = require('./package.json')
export default {
input: 'src/index.ts',
output: {
file: pkg.main,
format: 'umd',
name: camelCase(pkg.name),
},
watch: {
include: 'src/**',
},
plugins: [
typescript({
verbosity: 3,
tsconfigOverride: {
compilerOptions: {
target: 'es5',
declaration: false,
declarationDir: null,
},
},
useTsconfigDeclarationDir: true,
}),
],
}
tsconfig.json
{
"compilerOptions": {
"module": "esnext",
"target": "es6",
"lib": ["es6", "es7", "es2017", "dom"],
"moduleResolution": "node",
"declarationDir": "dist/types",
"declaration": true,
"allowSyntheticDefaultImports": true,
},
"include": [
"src/*"
]
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
variable declaration doesn't compile with rollup - Stack Overflow
When I compile my code with tsc -d --emitDeclarationOnly --declarationDir build/types everything builds fine, but with rollup -c throws an ...
Read more >@rollup/plugin-typescript - npm
When set to false, ignores any options specified in the config file. ... of outDir or declarationDir result in further TypeScript errors.
Read more >rollup-plugin-typescript2 - npm.io
Rollup plugin for typescript with compiler errors. ... If you want to override this behavior and instead use declarationDir , set useTsconfigDeclarationDir: ...
Read more >Rollup Plugin Typescript2: Compile TypeScript V2.0+. - Morioh
This plugin transpiles code, but doesn't change file extensions. ... Set to false if any other rollup plugins need access to declaration files....
Read more >TypeScript errors and how to fix them
error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier. Broken Code ❌. index.d ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ok, I put a minimal fix in for now, try on master.
With your options, I end up passing
declaration: false, declarationDir: null
totypescript.parseJsonConfigFileContent()
, and then typescript itself replacesdeclarationDir
with cwd. See values inraw
below.Either this is regression in typescript, or that code path was never fixed. I’ll open a case with them.