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.

TypeScript example

See original GitHub issue

It would be nice for a typescript example of workers. As right now, I can’t seem to find any type definitions for the most basic example:

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

/**
 * Fetch and log a given request object
 * @param {Request} request
 */
async function handleRequest(request) {
  console.log('Got request', request)
  const response = await fetch(request)
  console.log('Got response', response)
  return response
}

https://github.com/zeit/ncc could probably be used for generating the compiled bundle, as it supports typescript

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aequasicommented, Sep 20, 2019

would be nice to update that blog post to use babel-loader (the defacto standard for typescript + webpack now), instead of awesome-typescript-loader

0reactions
lukeedcommented, May 10, 2022

I know this is old, but this is now available in the /worker-typescript subdirectory.

You can create a project with it by visiting https://workers.new/typescript or locally via:

$ npm init cloudflare my-project worker-typescript
# or
$ yarn create cloudflare my-project worker-typescript
# or
$ pnpm create cloudflare my-project worker-typescript
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript for JavaScript Programmers
TypeScript knows the JavaScript language and will generate types for you in many cases. For example in creating a variable and assigning it...
Read more >
Typescript example: Beginners Guide To ... - AppDividend
Typescript is a typed superset of Javascript that compiles to plain JavaScript. TypeScript is open source language maintained by Microsoft.
Read more >
TypeScript Tutorial - Tutorialspoint
TypeScript is pure object oriented with classes, interfaces and statically typed like C# or Java. The popular JavaScript framework Angular 2.0 is written...
Read more >
TypeScript Tutorial - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python,...
Read more >
TypeScript Tutorial: What is, Interface, Enum, Array with Example
Above TypeScript example throws an error, but the same would have worked fine if it was with the var keyword. Variables using let...
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