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.

Can we export all types from the package?

See original GitHub issue

Title says it all. There are types like RichTextItemResponse and BlockObjectResponse that would be useful to have so we could create utils in our integrations that perform type checking

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:27
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
seancdaviscommented, Apr 1, 2022

This would also help me a lot. I’ve currently copied the api-endpoints.ts file to my project and exported all types, and it’s made type checking a much more pleasant process.

Another related suggestion is to use types for all objects, rather than embedding objects. For example, instead of this:

export type BlockObjectResponse =
  | {
      type: "paragraph";
      // ...
    }
  | {
      type: "heading_1";
      // ...
    }
  // ...

Do this:

export type ParagraphBlockResponse = {
  type: "paragraph";
  // ...
}

export type Heading1BlockResponse = {
  type: "heading_1";
  // ...
}

export type BlockObjectResponse = {
  ParagraphBlockResponse | Heading1BlockResponse | // ...
}

This way, if I’ve done the checking and am confident I’m working with a paragraph, then I can take advantage of the types this library is generating. Otherwise, I’m getting almost no benefit from the typings.


We do have the option to use the Extract utility, but it’s not a great experience. Here’s an example that demonstrates the complexity of this process.

5reactions
wcauchoiscommented, Jul 21, 2022

Hi, I recently made some changes to name many more response types and export them from this package in #319, so I am going to close this issue. These changes are available in version 2.1.0 of the SDK.

Note that I have not exported all types per the request from this issue, but every exported type requires a stability guarantee from us so I’ve been somewhat judicious. You can still extract types using TypeScript helpers like type indexes and Extract<>, where necessary. If there are any more specific issues around types please open a new GitHub issue, thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to export types in a TypeScript npm module
Without declaration files you can develop a package in TypeScript, compile it and expose it to other users as JavaScript code.
Read more >
export type * from 'somewhere' #48508 - GitHub
Just like export * from 'foo' , we should be able to export type * from 'foo' to re-export all types (and only...
Read more >
Documentation - Modules - TypeScript
Any declaration (such as a variable, function, class, type alias, or interface) can be exported by adding the export keyword. StringValidator.ts. ts. export ......
Read more >
Package exports - webpack
The exports field in the package.json of a package allows to declare which module should be used when using module requests like import...
Read more >
How to export a Type in TypeScript | bobbyhadz
Use a named export to export a type in TypeScript, e.g. export type Person = {} . The exported type can be imported...
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