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.

Emitting declaration files not working as expected

See original GitHub issue

When trying to emit code, the configuration is not working as expected. I tried different ways of configuring the tsc compiler, but with varying results. In some cases no code is emitted at all, and I havent been able to output the declaration files.

test.ts:

        const config = {
            ...
        };
        const ast = new Ast(config);
        ast.addSourceFiles('spec/common/**/*.ts');
        ast.emit();

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "declaration": true,
    "declarationDir": "spec/common/lib",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2015"
    ],
    "outDir": "spec/common/lib",
    "sourceMap": true
  },
  "include": [
    "spec/common"
  ]
}
  • When using the tsconfig.json:
        const config = {
            tsConfigFilePath: 'tsconfig.json',
            compilerOptions: {
                declarations: true,
            }
        };

In this case, the javascript and code mappings are outputted correctly to spec/common/lib. The declaration files are missing though.

  • When using
        const config = {
            tsConfigFilePath: 'tsconfig.json',
            compilerOptions: {
                out: 'spec/common/lib',
                declarations: true,
            }
        };

In this case, nothing gets outputted.

  • When omitting the declarations, nothing changes.
  • When omitting the tsconfig, nothing gets outputted. This is when including as wel as when omitting the out: 'spec/common/lib'.

Tested on arch linux & windows 10 with:

  • tsc 2.6.2
  • node 8.9.2
  • ts-simple-ast 0.92.0

Edit I failed to notice the upgrades from 1 to 3.2 in the last two weeks. The results seem to be the same, however.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
atasakcommented, Dec 15, 2017

Still not working… I have extracted a minimum (not-)working example from my project. Just run

npm install
npm run build
npm run run

the tests.ts file is located in spec/common and the output dir is set to spec/common/lib. In src/compiler/compiler/testschemer.ts, the line including the tsconfig is currently commented out. I cannot figure out what’s going wrong…

0reactions
dsherretcommented, Dec 16, 2017

Thanks, I just updated the docs! 😃

I see why they deprecated that compiler option now—too ambiguous.

Read more comments on GitHub >

github_iconTop Results From Across the Web

not emitting declaration files for `.d.ts` files · Issue #833 - GitHub
Emit declaration file for simple interface ts file. Actual Behaviour. No index.d.ts file generated. Steps to Reproduce the Problem. Try to run ...
Read more >
Typescript does not copy d.ts files to build - Stack Overflow
So tsc will not copy your custom types.d.ts file to the output ... .ts files), so tsc takes care of emitting the declarations...
Read more >
TypeScript library tips: Rollup your types! | by Martin Hochel
By default, TypeScript wont emit declaration files. To emit those, you'll need to enable following config within your tsconfig.json
Read more >
@rollup/plugin-typescript - npm
Declaration files are automatically included if they are listed in the files field in your tsconfig.json file. Source files in these fields are ......
Read more >
TSConfig Option: rootDir - TypeScript
Default: The longest common path of all non-declaration input files. ... Importantly, rootDir does not affect which files become part of the compilation....
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