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.

Expose `emitDts` to the public

See original GitHub issue

Is 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:

  1. make emitDts publicly available (and add some docs), maybe even expose it as a npx package for easy usage like npx emitDts --input ./src --output ./types
  2. 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:open
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mrtnbrodercommented, Jan 24, 2022

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

0reactions
Tymekcommented, Jan 27, 2022

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:

  // package.json
  "bin": {
    "emitSvelteDts": "./dist/<cli>.js"
  }

Plus a param parser, and since EmitDtsConig already enables configuration, it should be possible to write an external tool to run that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Emirates Exposed: Inside The Giant's Market Dominance
Emirates Exposed : Inside The Giant's Market Dominance. By James Pearson ... Emirates is the world's fourth-largest international airline.
Read more >
Dubai government considering Emirates IPO - airline president
The Dubai government is considering an initial public offering of Emirates airline, the flagship carrier's President Tim Clark said on ...
Read more >
Your Safety | COVID-19 information hub | Help - Emirates
Travel safely from door to door ... Follow the journey through our enhanced safety and disinfection measures at the airport and on your...
Read more >
This is How Emirates Responded to Our Cabin Crew Exposé ...
A few days ago, we published a post that shone a light on what it's like to work as cabin crew at the...
Read more >
Exposing The REAL United Arab Emirates (UAE) - Twitter
There are no human rights in the UAE. From members of the ruling family to holiday makers, ex-pats & business people, abuse is...
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