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.

Export type definitions

See original GitHub issue

Would it be possible to export the type definitions in index.d.ts? That would make it possible to use the types in JavaScript projects.

Here’s an example of how PageFunction could be used:

import { PagesFunction } from '@cloudflare/workers-types';

/** @type {PagesFunction} */
export async function onRequest(context) {
}

It’s also possible to import directly in the comment such as SvelteKit does it.

/** @type {import('@sveltejs/kit').RequestHandler} */
export async function get({ params }) {

}

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:16
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mrbbotcommented, Oct 21, 2022

Hey! 👋 Thanks for reporting this, we’re actively thinking about ways of fixing this in the next major version of workers-types using the new type generation system. 👍

2reactions
thatmattlovecommented, Sep 27, 2022

For anyone coming across this issue, I’ve released a (hopefully temporary) package as a workaround:

cloudflare-workers-types-esm

Mostly just using the TS library to copy the @cloudflare/workers-types programmatically and add export clauses to them, coupled with some Github Actions black magic to semi-automatically keep the package in sync with @cloudflare/workers-types.

It’s been wildly useful in my projects so far, so I plan to keep it active until this issue is resolved.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Modules .d.ts - TypeScript
The types which are exported can then be re-used by consumers of the modules using either import or import type in TypeScript code...
Read more >
How to export/import a only a type definition in TypeScript
js export the type myType using export type myType = {id: number}; and the file main.js imports the type using import type {myType}...
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 >
How to export type definitions for third-party package? - Reddit
I'm writing a package that uses a third party package that doesn't include its own typescript definitions. I've written my own .d.ts ...
Read more >
export type * from 'somewhere' #48508 - GitHub
So export type * from "foo" would export everything that export * from "foo" exports, values included, but those values would only be ......
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