gulp-typescript icon indicating copy to clipboard operation
gulp-typescript copied to clipboard

Definitions are not created

Open Astra-RX opened this issue 3 years ago • 2 comments

Expected behavior:

Generate d.ts when { "declaration": true } assigned.

Actual behavior:

Only js files generated, tsconfig.json works fine with tsc directly.

Your gulpfile:

Include your gulpfile, or only the related task (with ts.createProject).

// tsc
const tsProject = ts.createProject('tsconfig.json')
function tsc() {
  const tsResult = tsProject.src().pipe(tsProject())

  return merge([
    tsResult.js,
    tsResult.dts
  ])
  .pipe(gulp.dest(ESM_DIR))
}

tsconfig.json

Include your tsconfig, if related to this issue.

{
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "./.cache/",
    "target": "es6",
    "declaration": true,
    "jsx": "react-jsx",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "allowSyntheticDefaultImports": true,
    "removeComments": true,
    "sourceMap": true
  },
  "exclude": ["node_modules", "dist", "es", "development"],
  "include": ["typings.d.ts", "src"]
}

Code

Include your TypeScript code, if necessary.


Besides, I checked the tsProject() object, and found "declaration" within the "config" part is always false, no matter what the tsconfig.json or the setting param is.

Environment: [email protected] [email protected] [email protected]

Astra-RX avatar Mar 10 '21 05:03 Astra-RX

I dug the source a little and found the problem came from this line, but I don't see the reason why these options are related to the isolatedModules which is also not mentioned in official docs.

Astra-RX avatar Mar 10 '21 07:03 Astra-RX

isolatedModules: false saved me so much time, thank you @Artoria-0x04 !

TSMMark avatar Apr 10 '22 21:04 TSMMark