Logo

dev-resources.site

for different kinds of informations.

How to fix [deno-ts 2339] in the code for Deno Deploy

Published at
8/28/2021
Categories
deno
denodeploy
typescript
lsp
Author
kawarimidoll
Categories
4 categories in total
deno
open
denodeploy
open
typescript
open
lsp
open
Author
12 person written this
kawarimidoll
open
How to fix [deno-ts 2339] in the code for Deno Deploy

I am studying Deno Deploy.

This article summarizes how to deal with the [deno-ts 2339] error I encountered while writing code for Deno Deploy.

Errors that occur

The error is the one displayed in the editor, [deno-ts 2339] [E] Property 'respondWith' does not exist on type 'Event'.

As an example, we will use the code from the Hello World page of the official documentation:

// server.ts
addEventListener("fetch", (event) => {
  const response = new Response("Hello World!", {
    headers: { "content-type": "text/plain" },
  });
  event.respondWith(response);
});
Enter fullscreen mode Exit fullscreen mode

Even with all this code, the error occurs.

err

There is a warning that "respondWith is not defined in Event".

It can be ignored by the Deno Deploy environment and deployctl, and deno lint does not get particularly angry.
In other words, LSP is just giving you a warning, and you don't need to worry about it.
However, it is not very pleasant to keep getting errors during development. To be honest, it bothers me.

How to deal with it

An issue about it was raised in the deploy_feedback repository.

https://github.com/denoland/deploy_feedback/issues/13

And this issue was mentioned. We can use this method.

https://github.com/denoland/deployctl/issues/24#issuecomment-819272065

First, generate a type definition file.

❯ deployctl types > deploy.d.ts
Enter fullscreen mode Exit fullscreen mode

Next, add Triple-Slash Directives on the first part in server.ts.

https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html

/// <reference path="./deploy.d.ts" />

addEventListener("fetch", (event) => {
  const response = new Response("Hello Deno Deploy!", {
    headers: { "content-type": "text/plain" },
  });
  event.respondWith(response);
});
Enter fullscreen mode Exit fullscreen mode

This will remove the error.

clean

But now deployctl run . /server.ts fails.

To make it work correctly, you need to add the libs option at runtime.

❯ deployctl run --libs="" ./server.ts
Enter fullscreen mode Exit fullscreen mode

This completes the error handling and adjusting the command for execution.

Use task runner

It is tedious to type the options every time.
You can use Velociraptor, a task runner for Deno, to register the commands to be entered each time.

https://velociraptor.run/

Add the following description to velociraptor.yml.

scripts:
  dev:
    desc: Starts local server
    cmd: deployctl run --libs="" --watch ./server.ts
Enter fullscreen mode Exit fullscreen mode

You can now start a local server with vr dev.

❯ vr dev
Enter fullscreen mode Exit fullscreen mode

Closure

Personally, I think that more and more Deno development will be written with the assumption that it will run on Deno Deploy.
That's why I included it in my template repository.

https://github.com/kawarimidoll/deno-dev-template

This is a translation of the following article.
Please leave comments if there are any mistakes in the translation.

https://zenn.dev/kawarimidoll/articles/efed8ada433f24

lsp Article's
30 articles in total
Favicon
How to Setup Vim for Kotlin Development
Favicon
Managing LSPs in Neovim: Enable/Disable for the Entire Session
Favicon
Integrating the ruff language server
Favicon
Series Belajar Solid Principle - Liskov Substitution Principle (LSP)
Favicon
Avoid conflicts between denols and tsserver in Neovim
Favicon
Avoid conflicts between denols and tsserver in Neovim
Favicon
Implementing Payment Gateways with the Liskov Substitution Principle
Favicon
SOLID Principles: Liskov Substitution Principle (LSP)
Favicon
Configure Helix to use ElixirLS
Favicon
The Power of Liskov Substitution Principle in Improving Software Design
Favicon
Neovim config from scratch (Part II)
Favicon
Neovim config from scratch (Part I)
Favicon
Integrating a Language Server (LSP) in a VS Code Extension
Favicon
My Neovim setup for React, TypeScript, Tailwind CSS, etc
Favicon
How i setup neovim for speed up React, Js, Ts, etc
Favicon
Solve nvim lsp denols vs tsserver clash
Favicon
Perl Navigator - Language Server for Perl
Favicon
Neovim LSP Setup + Code Completion Engine
Favicon
NeoVim: init.lua, built in LSP e mais
Favicon
How to fix [deno-ts 2339] in the code for Deno Deploy
Favicon
SOLID e o princípio do 6 por meia dúzia
Favicon
Java LSP in Sublime Text
Favicon
Neovim: Migrando do coc.vim para nvim-lsp
Favicon
Integrating Scala Metals with Doom Emacs using LSP on Pop!_OS/Ubuntu 20.04 LTS
Favicon
Builtin Solidity Language Server
Favicon
Liskov Substitution Principle
Favicon
Emacs as SQL client with LSP
Favicon
Vim Configuration from Minimal to Complete
Favicon
LSP and ISP: The LI of SOLID
Favicon
Go LSP in Sublime Text

Featured ones: