Include global.d.ts in dist dir
See original GitHub issueWhat happens and why it is wrong
I’m sure this issue should exists already but I cannot find it. So it’s probably my fault 😃
My project includes a bunch of files under /src
and a /src/global.d.ts
file with some (not all) type declarations. The problem is that, the build declaration files do not include declarations defined in that file.
Environment
Versions
- typescript: 3.5.3
- rollup: 1.17.0
- rollup-plugin-typescript2: 0.22.1
rollup.config.js
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
const isProd = process.env.NODE_ENV === 'production';
export default [
{
input: 'src/index.ts',
external: ['events'],
plugins: [
typescript({
clean: isProd,
}),
],
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' },
],
},
];
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": "es5"
},
"exclude": [
"node_modules",
"dist",
"**/*.svg",
"src/**/*.test.*",
// "src/mocks"
],
"include": [
"src",
"src/**/*.d.ts",
"src/global.d.ts",
]
}
package.json
Not relevant
plugin output with verbosity 3
log:
> NODE_ENV=production rollup -c
src/index.ts → dist/router.cjs.js, dist/router.esm.js...
rpt2: built-in options overrides: {
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"noEmit": false,
"inlineSourceMap": false,
"outDir": "/home/fabrizio/Modelli/Projects/router.js/.rpt2_cache/placeholder",
"moduleResolution": 2,
"allowNonTsExtensions": true,
"declarationDir": "/home/fabrizio/Modelli/Projects/router.js"
}
rpt2: parsed tsconfig: {
"options": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"lib.dom.d.ts",
"lib.dom.iterable.d.ts",
"lib.esnext.d.ts"
],
"module": 6,
"moduleResolution": 2,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"resolveJsonModule": true,
"rootDir": "/home/fabrizio/Modelli/Projects/router.js/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": 1,
"configFilePath": "/home/fabrizio/Modelli/Projects/router.js/tsconfig.json",
"noEmitHelpers": false,
"importHelpers": true,
"noResolve": false,
"noEmit": false,
"inlineSourceMap": false,
"outDir": "/home/fabrizio/Modelli/Projects/router.js/.rpt2_cache/placeholder",
"allowNonTsExtensions": true,
"declarationDir": "/home/fabrizio/Modelli/Projects/router.js"
},
"fileNames": [
"/home/fabrizio/Modelli/Projects/router.js/src/global.d.ts",
"/home/fabrizio/Modelli/Projects/router.js/src/index.ts",
"/home/fabrizio/Modelli/Projects/router.js/src/router.ts",
"/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts",
"/home/fabrizio/Modelli/Projects/router.js/src/mocks/testEngine.ts"
],
"typeAcquisition": {
"enable": false,
"include": [],
"exclude": []
},
"raw": {
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"module": "esnext",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true,
"target": "es5"
},
"exclude": [
"node_modules",
"dist",
"**/*.svg",
"src/**/*.test.*"
],
"include": [
"src",
"src/**/*.d.ts",
"src/global.d.ts"
],
"compileOnSave": false
},
"errors": [],
"wildcardDirectories": {
"/home/fabrizio/Modelli/Projects/router.js/src": 1
},
"compileOnSave": false,
"configFileSpecs": {
"includeSpecs": [
"src",
"src/**/*.d.ts",
"src/global.d.ts"
],
"excludeSpecs": [
"node_modules",
"dist",
"**/*.svg",
"src/**/*.test.*"
],
"validatedIncludeSpecs": [
"src",
"src/**/*.d.ts",
"src/global.d.ts"
],
"validatedExcludeSpecs": [
"node_modules",
"dist",
"**/*.svg",
"src/**/*.test.*"
],
"wildcardDirectories": {
"/home/fabrizio/Modelli/Projects/router.js/src": 1
}
}
}
rpt2: typescript version: 3.5.3
rpt2: tslib version: 1.10.0
rpt2: rollup version: 1.17.0
rpt2: rollup-plugin-typescript2 version: 0.22.1
rpt2: plugin options:
{
"clean": true,
"verbosity": 3,
"check": true,
"cacheRoot": "/home/fabrizio/Modelli/Projects/router.js/.rpt2_cache",
"include": [
"*.ts+(|x)",
"**/*.ts+(|x)"
],
"exclude": [
"*.d.ts",
"**/*.d.ts"
],
"abortOnError": true,
"rollupCommonJSResolveHack": false,
"useTsconfigDeclarationDir": false,
"tsconfigOverride": {},
"transformers": [],
"tsconfigDefaults": {},
"objectHashIgnoreUnknownHack": false,
"typescript": "version 3.5.3"
}
rpt2: rollup config:
{
"chunkGroupingSize": 5000,
"experimentalCacheExpiry": 10,
"external": [
"events"
],
"inlineDynamicImports": false,
"input": "src/index.ts",
"perf": false,
"plugins": [
{
"name": "rpt2"
}
],
"strictDeprecations": false
}
rpt2: tsconfig path: /home/fabrizio/Modelli/Projects/router.js/tsconfig.json
rpt2: included:
[
"*.ts+(|x)",
"**/*.ts+(|x)"
]
rpt2: excluded:
[
"*.d.ts",
"**/*.d.ts"
]
rpt2: transpiling '/home/fabrizio/Modelli/Projects/router.js/src/index.ts'
rpt2: generated declarations for '/home/fabrizio/Modelli/Projects/router.js/src/index.ts'
rpt2: dependency '/home/fabrizio/Modelli/Projects/router.js/src/router.ts'
rpt2: imported by '/home/fabrizio/Modelli/Projects/router.js/src/index.ts'
rpt2: resolving './router' imported by '/home/fabrizio/Modelli/Projects/router.js/src/index.ts'
rpt2: to '/home/fabrizio/Modelli/Projects/router.js/src/router.ts'
rpt2: dependency '/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts'
rpt2: imported by '/home/fabrizio/Modelli/Projects/router.js/src/index.ts'
rpt2: resolving './engines/BrowserHistoryEngine' imported by '/home/fabrizio/Modelli/Projects/router.js/src/index.ts'
rpt2: to '/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts'
rpt2: transpiling '/home/fabrizio/Modelli/Projects/router.js/src/router.ts'
rpt2: generated declarations for '/home/fabrizio/Modelli/Projects/router.js/src/router.ts'
rpt2: dependency '/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts'
rpt2: imported by '/home/fabrizio/Modelli/Projects/router.js/src/router.ts'
rpt2: resolving './engines/BrowserHistoryEngine' imported by '/home/fabrizio/Modelli/Projects/router.js/src/router.ts'
rpt2: to '/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts'
rpt2: transpiling '/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts'
rpt2: generated declarations for '/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts'
rpt2: generating target 1
rpt2: rolling caches
rpt2: generating missed declarations for '/home/fabrizio/Modelli/Projects/router.js/src/mocks/testEngine.ts'
rpt2: writing declarations for '/home/fabrizio/Modelli/Projects/router.js/src/index.ts' to '/home/fabrizio/Modelli/Projects/router.js/dist/index.d.ts'
rpt2: writing declarations for '/home/fabrizio/Modelli/Projects/router.js/src/router.ts' to '/home/fabrizio/Modelli/Projects/router.js/dist/router.d.ts'
rpt2: writing declarations for '/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts' to '/home/fabrizio/Modelli/Projects/router.js/dist/engines/BrowserHistoryEngine.d.ts'
rpt2: writing declarations for '/home/fabrizio/Modelli/Projects/router.js/src/mocks/testEngine.ts' to '/home/fabrizio/Modelli/Projects/router.js/dist/mocks/testEngine.d.ts'
rpt2: generating target 2
rpt2: rolling caches
rpt2: writing declarations for '/home/fabrizio/Modelli/Projects/router.js/src/index.ts' to '/home/fabrizio/Modelli/Projects/router.js/dist/index.d.ts'
rpt2: writing declarations for '/home/fabrizio/Modelli/Projects/router.js/src/router.ts' to '/home/fabrizio/Modelli/Projects/router.js/dist/router.d.ts'
rpt2: writing declarations for '/home/fabrizio/Modelli/Projects/router.js/src/engines/BrowserHistoryEngine.ts' to '/home/fabrizio/Modelli/Projects/router.js/dist/engines/BrowserHistoryEngine.d.ts'
rpt2: writing declarations for '/home/fabrizio/Modelli/Projects/router.js/src/mocks/testEngine.ts' to '/home/fabrizio/Modelli/Projects/router.js/dist/mocks/testEngine.d.ts'
(!) `this` has been rewritten to `undefined`
https://rollupjs.org/guide/en/#error-this-is-undefined
src/router.ts
1: var _this = this;
^
2: import * as tslib_1 from "tslib";
3: import BrowserHistoryEngine from './engines/BrowserHistoryEngine';
created dist/router.cjs.js, dist/router.esm.js in 1.6s
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to configure custom global interfaces (.d.ts files) for ...
Anything in a script will be global. So if you define your interfaces in a script it will be available globally throughout your...
Read more >Documentation - Creating .d.ts Files from .js files - TypeScript
TypeScript replicates the node resolution for modules in a package.json , with an additional step for finding .d.ts files. Roughly, the resolution will...
Read more >Handbook - Creating .d.ts Files from .js files - TypeScript
TypeScript replicates the node resolution for modules in a package.json , with an additional step for finding .d.ts files. Roughly, the resolution will...
Read more >ts-node - npm
This error is thrown by node when a module is require() d, but node believes it should execute as native ESM. This can...
Read more >TypeScript configuration - Angular
This page covers some aspects of TypeScript configuration and the TypeScript environment that are important to Angular developers, including details about ...
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
Perfect thank you. I misinterpreted the role of the .d.ts files
Ah, I misunderstood your problem. Yep, existing declarations will not be touched. If you want them to appear in output declaratons, you have to manually export them somewhere.
Usually if you have internal d.ts file, it contains ambient types that are not defined in your module, but are present on the system. You are basically tell typescript “trust me, this stuff exists”. Those kind of types should not be a part of your module types. Your client is responsible for providing those (because client is responsible for setting up environment).
If you have types that are provided by your package (as opposed by environment), put them into a .ts file, and import it in all the right places.