Skip to content

transpileModule should set declarationMap = undefined when it sets declaration = undefined #31991

Description

transpileModule unsets the declaration compilerOption but not the declarationMap option. This causes an error diagnostic to be emitted when the compilerOptions passed to transpileModule have both of those options set to true. This can happen, for example, when using a tool that automatically loads a tsconfig and passes it to transpileModule. The reproduction link shows the exact diagnostic message.

I think the fix needs to happen at this line of code:
https://github.com/microsoft/TypeScript/blob/master/src/services/transpile.ts#L50

It needs to be followed by options.declarationMap = undefined;

Specifically, this was happening to me when using webpack's ts-loader. I have my tsconfig setup with declaration: true and declarationMap: true but ts-loader configured to transpileOnly, meaning it internally calls transpileModule.

TypeScript Version: 3.6.0-dev.20190619

Search Terms:

transpileModule declarationMap

Code

require('typescript').transpileModule('const foo = 1;', {compilerOptions: {declaration: true, declarationMap: true}, reportDiagnostics: true})

Expected behavior:

Zero diagnostics returned.

Actual behavior:

This diagnostic is returned:

Option 'declarationMap' cannot be specified without specifying option 'declaration' or option 'composite'.

Playground Link:

Instead I made a repl.it demonstration:
https://repl.it/@AndrewBradley/FavorableBlushingSale

Related Issues:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions