developit / microbundle

📦 Zero-configuration bundler for tiny modules.
https://npm.im/microbundle
MIT License
8.06k stars 361 forks source link

ts file which has declarations only will not emit corresponding d.ts #868

Closed littlee closed 3 years ago

littlee commented 3 years ago

src: index.ts

import { T } from './model';
export function a(b: T) {}

model.ts

export type T = {
  a: string;
}

package.json

{
  "name": "my-lib",
  "version": "1.0.0",
  "types": "types/index.d.ts",
  "scripts": {
    "build": "microbundle"
  },
  "devDependencies": {
    "microbundle": "^0.13.3"
  }
}

after building, ./types directory has only one file, model.d.ts is missing image

rschristian commented 3 years ago

@littlee This happens because you (likely) haven't set your tsconfig.json up correctly. You need to make sure both files are included by your config, for example:

{
  ...
  "include": ["src/**/*"]
}

This ensures types/model.d.ts gets created. See https://github.com/ezolenko/rollup-plugin-typescript2/issues/106#issuecomment-415461839

littlee commented 3 years ago

🤦 alright

agilgur5 commented 2 years ago

Thought I'd update here that I fixed the root cause upstream in https://github.com/ezolenko/rollup-plugin-typescript2/pull/406, which was released in rpt2 0.34.0.

The tsconfig include workaround should no longer be necessary, and one can now use tsconfig files instead.