Expose `emitDts` to the public
See original GitHub issueIs your feature request related to a problem? Please describe. I’m currently working on a svelte component library written in typescript and while looking/searching for solutions to build/generate typescript types for my components, I came across several solutions like e.g. sveld, however, it wasn’t really what I was expecting and doesn’t even work correctly.
I then stumbled across svelte-kits package
feature and saw that it actually generated what I was looking for. While looking at the source code and figuring out how it’s generating the types, I saw that svelte2tsx
somewhat “hidden” emitDts
function does exactly what I want. Given a source input directory, it generates working typescript types for my svelte components.
Describe the solution you’d like I’d love to have either (at best both) solutions:
- make
emitDts
publicly available (and add some docs), maybe even expose it as a npx package for easy usage likenpx emitDts --input ./src --output ./types
- make it a rollup plugin
I’d prefer the latter one since it would be easy to integrate it into my current build setup. But it doesn’t matter that much.
Describe alternatives you’ve considered Like mentioned, there are none except sveld, who came close to what I wanted, but wasn’t the “100%” solution.
To help some others, here’s my current script to generate typescript types from a svelte src
directory.
(credits actually go the svelte-kit package source maintainers)
const svelte2tsx = require("svelte2tsx")
const path = require("path")
// source dir
const source = path.join(path.resolve(), "src")
// types dir
const declarationDir = path.join(path.resolve(), "types")
svelte2tsx.emitDts({
libRoot: source,
// !important, otherwise it doesn't generate types.
svelteShimsPath: require.resolve("svelte2tsx/svelte-shims.d.ts"),
declarationDir: "types",
})
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top GitHub Comments
It is public, just nowhere documented or mentioned. I had to “dig deep” for this. Let’s see if I can work on a rollup plugin for this myself. thanks
Oh, sorry, I didn’t get it at first. My use case is a bit different. I’d like to hook into it earlier, before emitting the files. To do the
npx
thing you suggested, it is a different change. Like:Plus a param parser, and since
EmitDtsConig
already enables configuration, it should be possible to write an external tool to run that.