esm-dev / esm.sh

The no-build CDN for modern web development.
https://esm.sh
MIT License
3.15k stars 151 forks source link

`x-typescript-types` header is not set for type-only module #433

Closed gr2m closed 1 year ago

gr2m commented 2 years ago

Failing module

import "https://esm.sh/@octokit-next/types-rest-api@2.5.0";

Error message

No error message. The x-typescript-types response header is not on esm.sh/@octokit-next/types-rest-api although they are specified, and although they exist

Additional info

gr2m commented 2 years ago

In case it's helpful, some more context. Here is an example deno script:

import { Octokit } from "https://esm.sh/@octokit-next/core";
import "https://esm.sh/@octokit-next/types-rest-api";

const octokit = new Octokit();

const { data } = await octokit.request("GET /");

// should be typed as string
data.current_user_url

When editing the above code in VS Code with the Deno extension, data is typed as unknown.

If the https://esm.sh/@octokit-next/types-rest-api import would work as expected, data.current_user_url would be typed as string. See this typescript playground for comparison

gr2m commented 2 years ago

I was able to workaround the problem by adding a dummy export to the package: https://esm.sh/@octokit-next/types-rest-api@2.5.1

ije commented 2 years ago

thanks for the details, I will add support for type only package!

gr2m commented 1 year ago

@ije did you have a chance to look into it? No worries if not, just checking in

ije commented 1 year ago

currently if you import module from https://github.com/@types/react, it will redirect to https://esm.sh/v104/@types/react@18.0.27/index.d.ts, i don't know if it works for types-rest-api? i saw you added a workaround to exports, maybe just remove it?

gr2m commented 1 year ago

the problem persists.

# no "x-typescript-types" header in v2.5.0
curl https://esm.sh/@octokit-next/types-rest-api@2.5.0\?dev -I | grep x-typescript-types:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0    21    0     0    0     0      0      0 --:--:--  0:00:05 --:--:--     0

# header is present after adding a dummy code export
curl https://esm.sh/@octokit-next/types-rest-api@2.5.1\?dev -I | grep x-typescript-types:
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0   278    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
x-typescript-types: https://esm.sh/v104/@octokit-next/types-rest-api@2.5.1/index.d.ts
ije commented 1 year ago

ok, i will fix this asap, thanks

zeke commented 1 year ago

Hi @ije. My team is blocked by this in https://github.com/replicate/openapi

Anything needed to help unblock a fix for it?

ije commented 1 year ago

Hi @ije. My team is blocked by this in https://github.com/replicate/openapi

@zeke I'm trying to fix this, but i can't access the repository, can you please provide a npm name instead? thanks!

ije commented 1 year ago

In case it's helpful, some more context. Here is an example deno script:

import { Octokit } from "https://esm.sh/@octokit-next/core";
import "https://esm.sh/@octokit-next/types-rest-api";

const octokit = new Octokit();

const { data } = await octokit.request("GET /");

// should be typed as string
data.current_user_url

When editing the above code in VS Code with the Deno extension, data is typed as unknown.

If the https://esm.sh/@octokit-next/types-rest-api import would work as expected, data.current_user_url would be typed as string. See this typescript playground for comparison

i fixed the x-typescript-types header in v119, but can not get the demo to work

gr2m commented 1 year ago

i fixed the x-typescript-types header in v119, but can not get the demo to work

Might be something else.

I can confirm that the access-control-expose-headers header is now set

curl https://esm.sh/@octokit-next/types-rest-api@2.5.0\?dev -I                           
HTTP/2 200 
date: Tue, 16 May 2023 16:58:34 GMT
content-type: application/javascript; charset=utf-8
access-control-allow-origin: *
cache-control: public, max-age=86400
vary: Origin,User-Agent
access-control-allow-methods: *
access-control-expose-headers: X-TypeScript-Types
x-typescript-types: https://esm.sh/v121/@octokit-next/types-rest-api@2.5.0/index.d.ts
report-to: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=qbLGsa2Dg%2BgvjV3aVJHoHl5vo3YusUEP4J6%2FljsZNQK5PtZcK19h36Kfke9jwbizWPziBtd7I%2BCainXfgbG%2FXiaBvOoct18d%2BLWRThjsClxrCJ5LQxc65fQ%3D"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 7c852a8d6aa67c67-LAX
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

I think it's safe to close this issue. I'll open a new one once I find out what causes the problem with the Deno Script.

ije commented 1 year ago

@gr2m thanks 🙏